Platforms to show: All Mac Windows Linux Cross-Platform

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
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.

Feedback, Comments & Corrections

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
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.

Feedback, Comments & Corrections

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
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.

Feedback, Comments & Corrections

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
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.

Feedback, Comments & Corrections

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
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.

Feedback, Comments & Corrections

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
Function: 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
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.

Feedback, Comments & Corrections

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
Function: 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
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.

Feedback, Comments & Corrections

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

Feedback, Comments & Corrections

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

Feedback, Comments & Corrections

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
Function: 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

Feedback, Comments & Corrections

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
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.

Feedback, Comments & Corrections

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
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.

Feedback, Comments & Corrections

WebView2ControlMBS.OpenDevToolsWindow
Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebView2 MBS WinFrameworks Plugin 20.5 ❌ No ✅ Yes ❌ No ❌ No Desktop only
Function: Opens the DevTools window for the current document in the WebView.
Notes: Does nothing if called when the DevTools window is already open.

Some examples using this method:

Feedback, Comments & Corrections

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
Function: 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

Feedback, Comments & Corrections

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
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.

Feedback, Comments & Corrections

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
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.

Feedback, Comments & Corrections

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

Feedback, Comments & Corrections

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
Function: Remove the corresponding JavaScript added using AddScriptToExecuteOnDocumentCreated with the specified script id.

Feedback, Comments & Corrections

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
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.

Feedback, Comments & Corrections

WebView2ControlMBS.Stop
Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebView2 MBS WinFrameworks Plugin 20.5 ❌ No ✅ Yes ❌ No ❌ No Desktop only
Function: Stop all navigations and pending resource fetches.
Notes: Does not stop scripts.

Feedback, Comments & Corrections

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

The biggest plugin in space...




Links
MBS Xojo Chart Plugins

Start Chat