Platforms to show: All Mac Windows Linux Cross-Platform

Back to WebView2ControlMBS control.

WebView2ControlMBS.AddScriptToExecuteOnDocumentCreated(JavaScript as String, tag as variant = nil)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebView2 MBS WinFrameworks Plugin 20.5 ❌ No ✅ Yes ❌ No ❌ No Desktop only
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.

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)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebView2 MBS WinFrameworks Plugin 20.5 ❌ No ✅ Yes ❌ No ❌ No Desktop only
Adds a URI and resource context filter to the WebResourceRequested event.

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

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebView2 MBS WinFrameworks Plugin 20.5 ❌ No ✅ Yes ❌ No ❌ No Desktop only
Returns true if the WebView can navigate to a previous page in the navigation history.

The HistoryChanged event will fire if CanGoBack changes value.

Returns false if the browser is not yet initialized.

WebView2ControlMBS.CanGoForward as Boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebView2 MBS WinFrameworks Plugin 20.5 ❌ No ✅ Yes ❌ No ❌ No Desktop only
Returns true if the WebView can navigate to a next page in the navigation history.

The HistoryChanged event will fire if CanGoForward changes value.

Returns false if the browser is not yet initialized.

WebView2ControlMBS.CapturePreview(ImageFormat as Integer = 0)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebView2 MBS WinFrameworks Plugin 20.5 ❌ No ✅ Yes ❌ No ❌ No Desktop only
Capture an image of what WebView is displaying.

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

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebView2 MBS WinFrameworks Plugin 22.2 ❌ No ✅ Yes ❌ No ❌ No Desktop only
Asks webview to clear current selection.

This is the reverse for SelectAll.

WebView2ControlMBS.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
Clears a host name mapping for local folder that was added by SetVirtualHostNameToFolderMapping.

hostName: The host name to be removed from the mapping.

WebView2ControlMBS.Copy

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebView2 MBS WinFrameworks Plugin 22.2 ❌ No ✅ Yes ❌ No ❌ No Desktop only
Asks webview to copy current selection to clipboard.

WebView2ControlMBS.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
Creates the WebView2PrintSettingsMBS object used by the PrintToPdf method.

WebView2ControlMBS.Cut

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebView2 MBS WinFrameworks Plugin 22.2 ❌ No ✅ Yes ❌ No ❌ No Desktop only
Asks webview to cut current selection.

May do a copy, if selection is read only.

WebView2ControlMBS.ExecuteScript(JavaScript as String, tag as variant = nil)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebView2 MBS WinFrameworks Plugin 20.5 ❌ No ✅ Yes ❌ No ❌ No Desktop only
Execute JavaScript code from the javascript parameter in the current top level document rendered in the WebView.
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

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebView2 MBS WinFrameworks Plugin 21.0 ❌ No ✅ Yes ❌ No ❌ No Desktop only
Execute JavaScript code from the javascript parameter in the current top level document rendered in the WebView.
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

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebView2 MBS WinFrameworks Plugin 20.5 ❌ No ✅ Yes ❌ No ❌ No Desktop only
Navigates the WebView to the previous page in the navigation history.

WebView2ControlMBS.GoForward

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebView2 MBS WinFrameworks Plugin 20.5 ❌ No ✅ Yes ❌ No ❌ No Desktop only
Navigates the WebView to the next page in the navigation history.

WebView2ControlMBS.HTMLText as String

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebView2 MBS WinFrameworks Plugin 21.1 ❌ No ✅ Yes ❌ No ❌ No Desktop only
Queries HTML text of the current website.
Example
dim web as WebView2ControlMBS // your control

dim text as string = web.plaintext
dim html as string = web.HTMLText

break // check in debugger

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.

WebView2ControlMBS.LoadHTML(HTML as String)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebView2 MBS WinFrameworks Plugin 20.5 ❌ No ✅ Yes ❌ No ❌ No Desktop only
Initiates a navigation to htmlContent as source HTML of a new document.

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)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebView2 MBS WinFrameworks Plugin 20.5 ❌ No ✅ Yes ❌ No ❌ No Desktop only
Cause a navigation of the top level document to the specified URI.

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

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebView2 MBS WinFrameworks Plugin 20.5 ❌ No ✅ Yes ❌ No ❌ No Desktop only
Opens the DevTools window for the current document in the WebView.

Does nothing if called when the DevTools window is already open.

WebView2ControlMBS.Paste

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebView2 MBS WinFrameworks Plugin 22.2 ❌ No ✅ Yes ❌ No ❌ No Desktop only
Asks webview to paste clipboard content into the current field.

This may do nothing if there is nothing to paste or nothing to receive (no field in focus).

WebView2ControlMBS.PlainText as String

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebView2 MBS WinFrameworks Plugin 21.1 ❌ No ✅ Yes ❌ No ❌ No Desktop only
Queries plain text of the current website.
Example
dim web as WebView2ControlMBS // your control

dim text as string = web.plaintext
dim html as string = web.HTMLText

break // check in debugger

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.

WebView2ControlMBS.PostWebMessageAsJson(webMessageAsJson as String)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebView2 MBS WinFrameworks Plugin 20.5 ❌ No ✅ Yes ❌ No ❌ No Desktop only
Post the specified webMessage to the top level document in this WebView.

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)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebView2 MBS WinFrameworks Plugin 20.5 ❌ No ✅ Yes ❌ No ❌ No Desktop only
This is a helper for posting a message that is a simple string rather than a JSON string representation of a JavaScript object..

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

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebView2 MBS WinFrameworks Plugin 22.2 ❌ No ✅ Yes ❌ No ❌ No Desktop only
Asks webview to show print dialog.

WebView2ControlMBS.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
Print the current page to PDF asynchronously with the provided settings.

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.

WebView2ControlMBS.Reload

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebView2 MBS WinFrameworks Plugin 20.5 ❌ No ✅ Yes ❌ No ❌ No Desktop only
Reload the current page.

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

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebView2 MBS WinFrameworks Plugin 20.5 ❌ No ✅ Yes ❌ No ❌ No Desktop only
Remove the corresponding JavaScript added using AddScriptToExecuteOnDocumentCreated with the specified script id.

WebView2ControlMBS.RemoveWebResourceRequestedFilter(URL as String, resourceType as Integer)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebView2 MBS WinFrameworks Plugin 20.5 ❌ No ✅ Yes ❌ No ❌ No Desktop only
Removes a matching WebResource filter that was previously added for the WebResourceRequested event.

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

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebView2 MBS WinFrameworks Plugin 22.2 ❌ No ✅ Yes ❌ No ❌ No Desktop only
Asks webview to select all text.

WebView2ControlMBS.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
Sets a mapping between a virtual host name and a folder path to make available to web sites via that host name.

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.

WebView2ControlMBS.Stop

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebView2 MBS WinFrameworks Plugin 20.5 ❌ No ✅ Yes ❌ No ❌ No Desktop only
Stop all navigations and pending resource fetches.

Does not stop scripts.

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


The biggest plugin in space...