HostObjectAsyncProxyBase class

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.

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.

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): Promise<any>;

Parameters

argArray

any

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

Returns

Promise<any>

A promise representing the converted value of the return value of the host object method invocation.

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): Promise<any>;

Parameters

propertyName

string

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

Returns

Promise<any>

A promise representing 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

A promise representing 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): Promise<any>;

Parameters

propertyName

string

Name of the property of which to set the value.

propertyValue

any

Value to set the property.

Returns

Promise<any>

A promise representing the converted value of the property of the host object's property. This promise only resolves after the property value has been changed.

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 to get the value of.

propertyValue

any

Value to set the property to.

Returns

any

A promise representing the value of the property after it is set. This promise only resolves after the property changes value.