Platforms to show: All Mac Windows Linux Cross-Platform
Back to DesktopWebView2ControlMBS control.
DesktopWebView2ControlMBS.AddScriptToExecuteOnDocumentCreated(JavaScript as String, tag as variant = nil)
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 21.5 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
This method injects a script that runs on all top-level document and child frame page navigations. This method runs asynchronously, and you must wait for the completion handler to finish before the injected script is ready to run. When this method completes, the handler's Invoke method is called with the id of the injected script. id is a string. To remove the injected script, use RemoveScriptToExecuteOnDocumentCreated.
Note that if an HTML document has sandboxing of some kind via sandbox properties or the Content-Security-Policy HTTP header this will affect the script run here. So, for example, if the 'allow-modals' keyword is not set then calls to the alert function will be ignored.
Calls AddScriptToExecuteOnDocumentCreatedCompleted event later when done.
DesktopWebView2ControlMBS.AddWebResourceRequestedFilter(URL as String, resourceType as Integer)
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 21.5 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
The URI parameter can be a wildcard string ('*': zero or more, '?': exactly one). See kWebResourceContext constants for description of resource context filters.
DesktopWebView2ControlMBS.CanGoBack as Boolean
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 21.5 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
The HistoryChanged event will fire if CanGoBack changes value.
Returns false if the browser is not yet initialized.
DesktopWebView2ControlMBS.CanGoForward as Boolean
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 21.5 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
The HistoryChanged event will fire if CanGoForward changes value.
Returns false if the browser is not yet initialized.
DesktopWebView2ControlMBS.CapturePreview(ImageFormat as Integer = 0)
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 21.5 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
Specify the format of the image with the imageFormat parameter. The resulting image binary data is passed to the CapturePreviewCompleted event.
Calls CapturePreviewCompleted event when done or failed.
DesktopWebView2ControlMBS.ClearSelection
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 22.2 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
This is the reverse for SelectAll.
DesktopWebView2ControlMBS.ClearVirtualHostNameToFolderMapping(hostName as String)
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 23.4 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
hostName: The host name to be removed from the mapping.
DesktopWebView2ControlMBS.Copy
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 22.2 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
DesktopWebView2ControlMBS.CreatePrintSettings as WebView2PrintSettingsMBS
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 23.2 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 22.2 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
May do a copy, if selection is read only.
DesktopWebView2ControlMBS.ExecuteScript(JavaScript as String, tag as variant = nil)
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 21.5 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
This will execute asynchronously and when complete, if a handler is provided in the ExecuteScriptCompletedHandler parameter, its Invoke method will be called with the result of evaluating the provided JavaScript. The result value is a JSON encoded string. If the result is undefined, contains a reference cycle, or otherwise cannot be encoded into JSON, the JSON null value will be returned as the string 'null'. Note that a function that has no explicit return value returns undefined. If the executed script throws an unhandled exception, then the result is also 'null'. This method is applied asynchronously. If the method is called after NavigationStarting event during a navigation, the script will be executed in the new document when loading it, around the time ContentLoading is fired. ExecuteScript will work even if IsScriptEnabled is set to false.
Calls ExecuteScriptCompleted event later.
DesktopWebView2ControlMBS.ExecuteScriptSync(JavaScript as String, byref ErrorCode as Integer) as String
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 21.5 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
Same as ExecuteScript, but waits for event and returns result directly.
errorCode is zero on success.
Result is JSON as text, e.g. "null" if there is no result.
DesktopWebView2ControlMBS.GoBack
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 21.5 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
DesktopWebView2ControlMBS.GoForward
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 21.5 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
DesktopWebView2ControlMBS.HTMLText as String
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 21.5 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
Please don't call directly from NavigationCompleted event since that can freeze. Better use timer.CallLater to call a method later to do this a millisecond later.
DesktopWebView2ControlMBS.LoadHTML(HTML as String)
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 21.5 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
The htmlContent parameter may not be larger than 2 MB in total size. The origin of the new page will be about:blank.
DesktopWebView2ControlMBS.LoadURL(URL as String)
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 21.5 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
See the navigation events for more information. Note that this starts a navigation and the corresponding NavigationStarting event will fire sometime after this Navigate call completes.
DesktopWebView2ControlMBS.OpenDevToolsWindow
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 21.5 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
Does nothing if called when the DevTools window is already open.
DesktopWebView2ControlMBS.Paste
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 22.2 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
This may do nothing if there is nothing to paste or nothing to receive (no field in focus).
DesktopWebView2ControlMBS.PlainText as String
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 21.5 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
Please don't call directly from NavigationCompleted event since that can freeze. Better use timer.CallLater to call a method later to do this a millisecond later.
DesktopWebView2ControlMBS.PostWebMessageAsJson(webMessageAsJson as String)
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 21.5 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
The top level document's window.chrome.webview's message event fires. JavaScript in that document may subscribe and unsubscribe to the event via the following:
window.chrome.webview.addEventListener('message', handler)
window.chrome.webview.removeEventListener('message', handler)
The event args is an instance of MessageEvent. The IsWebMessageEnabled setting must be true or this method will fail with E_INVALIDARG. The event arg's data property is the webMessage string parameter parsed as a JSON string into a JavaScript object. The event arg's source property is a reference to the window.chrome.webview object. See add_WebMessageReceived for information on sending messages from the HTML document in the WebView to the host. This message is sent asynchronously. If a navigation occurs before the message is posted to the page, then the message will not be sent.
DesktopWebView2ControlMBS.PostWebMessageAsString(webMessageAsString as String)
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 21.5 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
This behaves in exactly the same manner as PostWebMessageAsJson but the window.chrome.webview message event arg's data property will be a string with the same value as webMessageAsString. Use this instead of PostWebMessageAsJson if you want to communicate via simple strings rather than JSON objects.
DesktopWebView2ControlMBS.Print
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 22.2 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
DesktopWebView2ControlMBS.PrintToPdf(Path as String, PrintSettings as WebView2PrintSettingsMBS = nil)
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 23.1 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
Use Path to specify the path to the PDF file. The host should provide an absolute path, including file name. If the path points to an existing file, the file will be overwritten. If the path is not valid, the method fails with E_INVALIDARG.
The async PrintToPdf operation completes when the data has been written to the PDF file. At this time the PrintCompleted event is invoked. If the application exits before printing is complete, the file is not saved. Only one Printing operation can be in progress at a time. If PrintToPdf is called while a printing operation is in progress, the event is immediately invoked with isSuccessful set to false.
Requires WebView2 in version 1.0.1020.30 or later.
DesktopWebView2ControlMBS.Reload
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 21.5 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
This is similar to navigating to the URI of current top level document including all navigation events firing and respecting any entries in the HTTP cache. But, the back/forward history will not be modified.
DesktopWebView2ControlMBS.RemoveScriptToExecuteOnDocumentCreated(ID as String
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 21.5 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
DesktopWebView2ControlMBS.RemoveWebResourceRequestedFilter(URL as String, resourceType as Integer)
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 21.5 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
If the same filter was added multiple times, then it will need to be removed as many times as it was added for the removal to be effective. Raises exception with E_INVALIDARG for a filter that was never added.
DesktopWebView2ControlMBS.SelectAll
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 22.2 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
DesktopWebView2ControlMBS.SetVirtualHostNameToFolderMapping(hostName as String, folderPath as String, accessKind as Integer)
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 23.4 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
hostName: A virtual host name.
folderPath: A folder path name to be mapped to the virtual host name. The length must not exceed the Windows MAX_PATH limit.
accessKind: The level of access to resources under the virtual host from other sites.
See kHostResourceAccessKind* constants.
DesktopWebView2ControlMBS.Stop
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 21.5 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
Does not stop scripts.
The items on this page are in the following plugins: MBS WinFrameworks Plugin.