Platforms to show: All Mac Windows Linux Cross-Platform

/WinFrameworks/WebView2 Test


Required plugins for this example: MBS WinFrameworks Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /WinFrameworks/WebView2 Test

This example is the version from Thu, 22th Mar 2023.

Project "WebView2 Test.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub Open() #If XojoVersion > 2020 // Xojo 2020 has a fix for shared methods. Dim v As String = WebView2ControlMBS.AvailableCoreWebView2BrowserVersionString System.DebugLog "Version: "+v #EndIf End EventHandler
End Class
Class MainWindow Inherits Window
Control web Inherits WebView2ControlMBS
ControlInstance web Inherits WebView2ControlMBS
EventHandler Sub AddScriptToExecuteOnDocumentCreatedCompleted(JavaScript as String, ErrorCode as Integer, ID as String, Tag as Variant) System.DebugLog CurrentMethodName+" "+ID End EventHandler
EventHandler Sub CapturePreviewCompleted(ImageFormat as Integer, ErrorCode as Integer, PictureData as String) If PictureData.Length > 0 Then Dim file As FolderItem = SpecialFolder.Desktop.Child("webview.png") Dim b As BinaryStream = BinaryStream.Create(file, True) b.Write PictureData b.Close file.Launch End If End EventHandler
EventHandler Sub Close() System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub Configure() System.DebugLog CurrentMethodName Dim folder As FolderItem = SpecialFolder.ApplicationData.Child("MyApp") folder.CreateAsFolder Me.UserDataFolder = folder.NativePath End EventHandler
EventHandler Sub ContentLoading(isErrorPage as Boolean, NavigationID as UInt64) System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub DocumentTitleChanged() System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub ExecuteScriptCompleted(JavaScript as String, ErrorCode as Integer, resultObjectAsJson as String, Tag as Variant) System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub HistoryChanged() System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub NavigationCompleted(isSuccess as Boolean, ErrorStatus as Integer, NavigationID as UInt64) System.DebugLog CurrentMethodName End EventHandler
EventHandler Function NavigationStarting(URL as String, IsUserInitiated as Boolean, IsRedirected as Boolean, NavigationID as UInt64) As Boolean System.DebugLog CurrentMethodName+": "+URL End EventHandler
EventHandler Sub Open() System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub Opened() System.DebugLog CurrentMethodName // enable transparent background web.DefaultBackgroundColor = &cFFFFFFFF End EventHandler
EventHandler Sub PermissionRequested(URL as String, PermissionKind as Integer, IsUserInitiated as Boolean, byref State as Integer) System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub ProcessFailed(processFailedKind as Integer) System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub SourceChanged(isNewDocument as Boolean) System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub WebMessageReceived(Source as String, webMessageAsJson as String, webMessageAsString as String) System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub WindowCloseRequested() System.DebugLog CurrentMethodName End EventHandler
End Control
EventHandler Sub EnableMenuItems() CommandsGoBack.Enabled = web.CanGoBack CommandsGoForward.Enabled = web.CanGoForward CommandsShowdevelopertools.Enable CommandsSavePicture.enable End EventHandler
EventHandler Sub Open() System.DebugLog CurrentMethodName web.LoadURL "https://www.monkeybreadsoftware.de/" End EventHandler
Function CommandsCookies() As Boolean Dim cookiemanager As WebView2CookieManagerMBS = web.CookieManager // get all cookies synchronously Dim cookies() As WebView2CookieMBS = cookiemanager.GetCookiesSync // show them in window CookiesWindow.show(cookiemanager, cookies) Return True End Function
Function CommandsGoBack() As Boolean web.GoBack Return True End Function
Function CommandsGoForward() As Boolean web.GoForward Return True End Function
Function CommandsSavePicture() As Boolean web.CapturePreview web.kCapturePreviewImageFormatPNG Return True End Function
Function CommandsShowdevelopertools() As Boolean web.OpenDevToolsWindow Return True End Function
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
MenuItem CommandsMenu = "Commands"
MenuItem CommandsGoBack = "Go Back"
MenuItem CommandsGoForward = "Go Forward"
MenuItem CommandsShowdevelopertools = "Show developer tools"
MenuItem CommandsCookies = "Cookies"
MenuItem CommandsSavePicture = "Save Picture"
End MenuBar
Class CookiesWindow Inherits Window
Control List Inherits Listbox
ControlInstance List Inherits Listbox
EventHandler Function KeyDown(Key As String) As Boolean If Asc(key) = 8 Or Asc(key) = 127 Then // backspace or delete Dim SelectedRowIndex As Integer = Me.SelectedRowIndex If SelectedRowIndex >= 0 Then // we delete selected cookie Dim cookie As WebView2CookieMBS = Me.RowTagAt(SelectedRowIndex) cookiemanager.DeleteCookie cookie Me.RemoveRowAt(SelectedRowIndex) Return True End If End If End EventHandler
End Control
Sub Show(cookiemanager as WebView2CookieManagerMBS, cookies() as WebView2CookieMBS) // Calling the overridden superclass method. Self.cookiemanager = cookiemanager Dim List As Listbox = Self.List For Each cookie As WebView2CookieMBS In cookies Dim flags() As String If cookie.IsHttpOnly Then flags.Append "http only" end if If cookie.IsSecure Then flags.Append "secure" End If If cookie.IsSession Then flags.Append "session" End If List.AddRow cookie.Domain, cookie.Path, cookie.Name, cookie.Value, cookie.Expires.ToString, String.FromArray(flags, ", ") List.RowTagAt(List.LastAddedRowIndex) = cookie Next Super.Show() End Sub
Property cookiemanager As WebView2CookieManagerMBS
End Class
End Project

The items on this page are in the following plugins: MBS WinFrameworks Plugin.


The biggest plugin in space...