Platforms to show: All Mac Windows Linux Cross-Platform
WebView2ControlMBS.AddScriptToExecuteOnDocumentCreated(JavaScript as String, tag as variant = nil)
Function:
Add the provided JavaScript to a list of scripts that should be executed after the global object has been created, but before the HTML document has been parsed and before any other script included by the HTML document is executed.
Notes:
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.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 20.5 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
Notes:
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.
WebView2ControlMBS.AddWebResourceRequestedFilter(URL as String, resourceType as Integer)
Function:
Adds a URI and resource context filter to the WebResourceRequested event.
Notes: The URI parameter can be a wildcard string ('*': zero or more, '?': exactly one). See kWebResourceContext constants for description of resource context filters.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 20.5 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
Notes: The URI parameter can be a wildcard string ('*': zero or more, '?': exactly one). See kWebResourceContext constants for description of resource context filters.
WebView2ControlMBS.CanGoBack as Boolean
Function:
Returns true if the WebView can navigate to a previous page in the navigation history.
Notes:
The HistoryChanged event will fire if CanGoBack changes value.
Returns false if the browser is not yet initialized.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 20.5 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
Notes:
The HistoryChanged event will fire if CanGoBack changes value.
Returns false if the browser is not yet initialized.
WebView2ControlMBS.CanGoForward as Boolean
Function:
Returns true if the WebView can navigate to a next page in the navigation history.
Notes:
The HistoryChanged event will fire if CanGoForward changes value.
Returns false if the browser is not yet initialized.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 20.5 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
Notes:
The HistoryChanged event will fire if CanGoForward changes value.
Returns false if the browser is not yet initialized.
WebView2ControlMBS.CapturePreview(ImageFormat as Integer = 0)
Function:
Capture an image of what WebView is displaying.
Notes:
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.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 20.5 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
Notes:
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.
WebView2ControlMBS.ClearSelection
Function:
Asks webview to clear current selection.
Notes: This is the reverse for SelectAll.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 22.2 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
Notes: This is the reverse for SelectAll.
WebView2ControlMBS.Copy
Function:
Asks webview to copy current selection to clipboard.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 22.2 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
WebView2ControlMBS.Cut
Function:
Asks webview to cut current selection.
Notes: May do a copy, if selection is read only.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 22.2 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
Notes: May do a copy, if selection is read only.
WebView2ControlMBS.ExecuteScript(JavaScript as String, tag as variant = nil)
Function:
Execute JavaScript code from the javascript parameter in the current top level document rendered in the WebView.
Example:
Notes:
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.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 20.5 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
Example:
dim web as WebView2ControlMBS // your control
web.ExecuteScript "1+5" , "tag value"
// triggers ExecuteScriptCompeleted later with result "6"
web.ExecuteScript "window.chrome.webview.postMessage({'Test': 'Hello, world!'});"
// triggers later WebMessageReceived later
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.
WebView2ControlMBS.ExecuteScriptSync(JavaScript as String, byref ErrorCode as Integer) as String
Function:
Execute JavaScript code from the javascript parameter in the current top level document rendered in the WebView.
Example:
Notes:
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.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 21.0 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
Example:
dim web as WebView2ControlMBS // your control
dim errorCode as integer
dim s as string = web.ExecuteScriptSync("1+2", errorCode)
Break // s contains 3
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.
WebView2ControlMBS.GoBack
Function:
Navigates the WebView to the previous page in the navigation history.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 20.5 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
WebView2ControlMBS.GoForward
Function:
Navigates the WebView to the next page in the navigation history.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 20.5 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
WebView2ControlMBS.HTMLText as String
Function:
Queries HTML text of the current website.
Example:
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 21.1 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
Example:
dim web as WebView2ControlMBS // your control
dim text as string = web.plaintext
dim html as string = web.HTMLText
break // check in debugger
WebView2ControlMBS.LoadHTML(HTML as String)
Function:
Initiates a navigation to htmlContent as source HTML of a new document.
Notes: The htmlContent parameter may not be larger than 2 MB in total size. The origin of the new page will be about:blank.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 20.5 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
Notes: The htmlContent parameter may not be larger than 2 MB in total size. The origin of the new page will be about:blank.
WebView2ControlMBS.LoadURL(URL as String)
Function:
Cause a navigation of the top level document to the specified URI.
Notes: 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.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 20.5 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
Notes: 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.
WebView2ControlMBS.OpenDevToolsWindow
Function:
Opens the DevTools window for the current document in the WebView.
Notes: Does nothing if called when the DevTools window is already open.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 20.5 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
Notes: Does nothing if called when the DevTools window is already open.
WebView2ControlMBS.Paste
Function:
Asks webview to paste clipboard content into the current field.
Notes: This may do nothing if there is nothing to paste or nothing to receive (no field in focus).
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 22.2 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
Notes: This may do nothing if there is nothing to paste or nothing to receive (no field in focus).
WebView2ControlMBS.PlainText as String
Function:
Queries plain text of the current website.
Example:
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 21.1 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
Example:
dim web as WebView2ControlMBS // your control
dim text as string = web.plaintext
dim html as string = web.HTMLText
break // check in debugger
WebView2ControlMBS.PostWebMessageAsJson(webMessageAsJson as String)
Function:
Post the specified webMessage to the top level document in this WebView.
Notes:
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.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 20.5 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
Notes:
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.
WebView2ControlMBS.PostWebMessageAsString(webMessageAsString as String)
Function:
This is a helper for posting a message that is a simple string rather than a JSON string representation of a JavaScript object..
Notes: 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.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 20.5 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
Notes: 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.
WebView2ControlMBS.Print
Function:
Asks webview to show print dialog.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 22.2 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
WebView2ControlMBS.Reload
Function:
Reload the current page.
Notes: 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.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 20.5 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
Notes: 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.
WebView2ControlMBS.RemoveScriptToExecuteOnDocumentCreated(ID as String
Function:
Remove the corresponding JavaScript added using AddScriptToExecuteOnDocumentCreated with the specified script id.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 20.5 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
WebView2ControlMBS.RemoveWebResourceRequestedFilter(URL as String, resourceType as Integer)
Function:
Removes a matching WebResource filter that was previously added for the WebResourceRequested event.
Notes: 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.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 20.5 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
Notes: 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.
WebView2ControlMBS.SelectAll
Function:
Asks webview to select all text.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 22.2 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
WebView2ControlMBS.Stop
Function:
Stop all navigations and pending resource fetches.
Notes: Does not stop scripts.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | WebView2 | MBS WinFrameworks Plugin | 20.5 | ❌ No | ✅ Yes | ❌ No | ❌ No | Desktop only |
Notes: Does not stop scripts.
The items on this page are in the following plugins: MBS WinFrameworks Plugin.
Feedback: Report problem or ask question.
