WebView2Script package

Use the Microsoft Edge WebView2 control to embed web content into native applications. You can use the following window.chrome.webview JavaScript APIs along with native WebView2 APIs to communicate between native code and web code.

Classes

HostObjectAsyncProxy

An asynchronous host object proxy. Host objects added via CoreWebView2.AddHostObjectToScript are exposed as host object proxies using window.chrome.webview.hostObjects.{name}. Host object proxies are promises, and resolve to an object representing the host object. The promise is rejected if the app has not added an object with the name. When JavaScript code access a property or method of the object, a promise is returned. The promise resolves to the value that's returned from the host for the property or method. The promise is rejected in case of error; for example, no property or method on the object or parameters are not valid.

Host object proxies are JavaScript Proxy objects that intercept all property get, property set, and method invocations. Properties or methods that are a part of the Function or Object prototype are run in the JavaScript engine of the current document. Additionally any property or method in the chrome.webview.hostObjects.options.forceLocalProperties array are also run in the JavaScript engine of the current document. This defaults to including optional methods that have meaning in JavaScript like toJSON and Symbol.toPrimitive. Add more to the array as required.

HostObjectAsyncProxyBase

An asynchronous host object proxy. Host objects added via CoreWebView2.AddHostObjectToScript are exposed as host object proxies using window.chrome.webview.hostObjects.{name}. Host object proxies are promises, and resolve to an object representing the host object. The promise is rejected if the app has not added an object with the name. When JavaScript code access a property or method of the object, a promise is returned. The promise resolves to the value that's returned from the host for the property or method. The promise is rejected in case of error; for example, no property or method on the object, or parameters are not valid.

Host object proxies are JavaScript Proxy objects that intercept all property get, property set, and method invocations. Properties or methods that are a part of the Function or Object prototype are run in the JavaScript engine of the current document. Additionally any property or method in the chrome.webview.hostObjects.options.forceLocalProperties array are also run in the JavaScript engine of the current document. This defaults to including optional methods that have meaning in JavaScript like toJSON and Symbol.toPrimitive. Add more to the array as required.

HostObjectsAsyncRoot

Contains asynchronous proxies for all host objects added via CoreWebView2.AddHostObjectToScript as well as options to configure those proxies, and the container for synchronous proxies.

If you call coreWebView2.AddHostObjectToScript("myObject", object); in your native code, an asynchronous proxy for object is available to your web-side code, by using chrome.webview.hostObjects.myObject.

HostObjectsOptions

Contains options applicable to CoreWebView2.AddHostObjectToScript added script proxies.

HostObjectsSyncRoot

Contains synchronous proxies for all host objects added via CoreWebView2.AddHostObjectToScript.

If you call coreWebView2.AddHostObjectToScript("myObject", object); in your native code, a synchronous proxy for object is available to your web-side code, by using chrome.webview.hostObjects.sync.myObject.

HostObjectSyncProxy

A synchronous host object proxy. Host objects added via CoreWebView2.AddHostObjectToScript are exposed as host object proxies using window.chrome.webview.hostObjects.{name}. A host object proxy represent a host object.

Host object proxies are JavaScript Proxy objects that intercept all property get, property set, and method invocations. Properties or methods that are a part of the Function or Object prototype are run locally. Additionally any property or method in the chrome.webview.hostObjects.options.forceLocalProperties array is also run locally. This defaults to including optional methods that have meaning in JavaScript like toJSON and Symbol.toPrimitive. Add more to the array as required.

SharedBufferReceivedEvent

Event object for the chrome.webview.sharedbufferreceived event. This event is dispatched when CoreWebView2.PostSharedBufferToScript is successfully called.

WebView

window.chrome.webview is the class to access the WebView2-specific APIs that are available to the script running within WebView2 Runtime.

WebViewEventMap

Events of the WebView interface.

WebViewMessageEvent

Event object for the chrome.webview.webmessage event. This event is dispatched when CoreWebView2.PostWebMessage* is successfully called.