HostObjectSyncProxy class

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.

Extends

Methods

applyHostFunction(argArray)

Perform a method invocation on the host object that corresponds to this proxy.

All parameters are converted to call the host object method.

async()

A method which blocks and returns an asynchronous host object proxy for the same host object. For example, chrome.webview.hostObjects.sync.sample.methodCall() returns a synchronous host object proxy. Running the async method on this blocks and then returns an asynchronous host object proxy for the same host object: const asyncProxy = chrome.webview.hostObjects.sync.sample.methodCall().async().

getHostProperty(propertyName)

Perform a property get on the host object. Use this method to explicitly force a property get to occur remotely if a conflicting local method or property exists. For instance, proxy.toString() runs the local toString method on the proxy object. But proxy.applyHostFunction('toString') runs toString on the host proxied object instead.

getLocalProperty(propertyName)

Perform a property get locally on the proxy object. Use the methods to force getting a property on the host object proxy rather than on the host object it represents. For instance, proxy.unknownProperty gets the property named unknownProperty from the host proxied object. But proxy.getLocalProperty('unknownProperty') gets the value of the property unknownProperty on the proxy object.

setHostProperty(propertyName, propertyValue)

Perform a property set on the host object. Use this method to explicitly force a property set to occur remotely if a conflicting local method or property exists.

setLocalProperty(propertyName, propertyValue)

Perform a property set locally on the proxy object. Use the methods to force setting a property on the host object proxy rather than on the host object it represents. For instance, proxy.unknownProperty = 2 sets the property named unknownProperty on the host proxied object. But proxy.setLocalProperty('unknownProperty', 2) sets the value of the property unknownProperty on the proxy object.

Method Details

applyHostFunction(argArray)

Perform a method invocation on the host object that corresponds to this proxy.

All parameters are converted to call the host object method.

applyHostFunction(argArray?: any): any;

Parameters

argArray

any

An array of arguments to pass to the host object method invocation.

Returns

any

The converted value of the return value of the host object method invocation.

async()

A method which blocks and returns an asynchronous host object proxy for the same host object. For example, chrome.webview.hostObjects.sync.sample.methodCall() returns a synchronous host object proxy. Running the async method on this blocks and then returns an asynchronous host object proxy for the same host object: const asyncProxy = chrome.webview.hostObjects.sync.sample.methodCall().async().

async(): HostObjectAsyncProxy;

Returns

An asynchronous host object proxy for the same host object.

getHostProperty(propertyName)

Perform a property get on the host object. Use this method to explicitly force a property get to occur remotely if a conflicting local method or property exists. For instance, proxy.toString() runs the local toString method on the proxy object. But proxy.applyHostFunction('toString') runs toString on the host proxied object instead.

getHostProperty(propertyName: string): any;

Parameters

propertyName

string

String name of the property of which to get the value.

Returns

any

The converted value of the property of the host object's property.

getLocalProperty(propertyName)

Perform a property get locally on the proxy object. Use the methods to force getting a property on the host object proxy rather than on the host object it represents. For instance, proxy.unknownProperty gets the property named unknownProperty from the host proxied object. But proxy.getLocalProperty('unknownProperty') gets the value of the property unknownProperty on the proxy object.

getLocalProperty(propertyName: string): any;

Parameters

propertyName

string

Name of the property to get the value of.

Returns

any

The value of the property.

setHostProperty(propertyName, propertyValue)

Perform a property set on the host object. Use this method to explicitly force a property set to occur remotely if a conflicting local method or property exists.

setHostProperty(propertyName: string, propertyValue: any): any;

Parameters

propertyName

string

Name of the property of which to set the value.

propertyValue

any

Value to set the property to.

Returns

any

The converted value of the property of the host object's property.

setLocalProperty(propertyName, propertyValue)

Perform a property set locally on the proxy object. Use the methods to force setting a property on the host object proxy rather than on the host object it represents. For instance, proxy.unknownProperty = 2 sets the property named unknownProperty on the host proxied object. But proxy.setLocalProperty('unknownProperty', 2) sets the value of the property unknownProperty on the proxy object.

setLocalProperty(propertyName: string, propertyValue: any): any;

Parameters

propertyName

string

Name of the property of which to set the value.

propertyValue

any

Value to set the property to.

Returns

any

The value of the property after it is set.