HostObjectsOptions class

Contains options applicable to CoreWebView2.AddHostObjectToScript added script proxies.

Properties

defaultSyncProxy

When calling a method on a synchronous proxy, the result should also be a synchronous proxy. But in some cases, the sync or async context is lost (for example, when providing to native code a reference to a function, and then calling that function in native code). In these cases, the proxy will be asynchronous if this option is false, and synchronous if this option is true.

forceAsyncMethodMatches

This is an array of regular expressions. When calling a method on a synchronous proxy, the method call will be performed asynchronously if the method name matches a string or regular expression in this array. Setting this value to /Async$/ will make any method that ends with Async be an asynchronous method call. If an async method doesn't match here and isn't forced to be asynchronous, the method will be invoked synchronously, blocking execution of the calling JavaScript and then returning the resolution of the promise, rather than returning a promise.

This defaults to [].

forceLocalProperties

This is an array of host object property names that will be run locally, instead of being called on the native host object. This defaults to ['then', 'toJSON', Symbol.toString, Symbol.toPrimitive]. You can add other properties to specify that they should be run locally on the javascript host object proxy.

ignoreMemberNotFoundError

By default, an exception is thrown when attempting to get the value of a proxy property that doesn't exist on the corresponding native class. Setting this property to true changes the behavior to match Chakra WinRT projection (and general JavaScript) behavior of returning undefined with no error.

log

This is a callback delegate that will be called with debug information if non-null.

For example, you can set this to console.log.bind(console) to have it print debug information to the console, to help when troubleshooting host object usage.

By default this is null.

shouldPassTypedArraysAsArrays

By default, typed arrays are passed to the host as IDispatch. To instead pass typed arrays to the host as array, set this to true.

shouldSerializeDates

By default this is false, and javascript Date objects will be sent to host objects as a string using JSON.stringify.

You can set this property to true to have Date objects properly serialize as a VT_DATE when sending to the native host object, and have VT_DATE properties and return values create a JavaScript Date object.

Property Details

defaultSyncProxy

When calling a method on a synchronous proxy, the result should also be a synchronous proxy. But in some cases, the sync or async context is lost (for example, when providing to native code a reference to a function, and then calling that function in native code). In these cases, the proxy will be asynchronous if this option is false, and synchronous if this option is true.

defaultSyncProxy: boolean;

Property Value

boolean

forceAsyncMethodMatches

This is an array of regular expressions. When calling a method on a synchronous proxy, the method call will be performed asynchronously if the method name matches a string or regular expression in this array. Setting this value to /Async$/ will make any method that ends with Async be an asynchronous method call. If an async method doesn't match here and isn't forced to be asynchronous, the method will be invoked synchronously, blocking execution of the calling JavaScript and then returning the resolution of the promise, rather than returning a promise.

This defaults to [].

forceAsyncMethodMatches: RegExp[];

Property Value

RegExp[]

forceLocalProperties

This is an array of host object property names that will be run locally, instead of being called on the native host object. This defaults to ['then', 'toJSON', Symbol.toString, Symbol.toPrimitive]. You can add other properties to specify that they should be run locally on the javascript host object proxy.

forceLocalProperties: string[];

Property Value

string[]

ignoreMemberNotFoundError

By default, an exception is thrown when attempting to get the value of a proxy property that doesn't exist on the corresponding native class. Setting this property to true changes the behavior to match Chakra WinRT projection (and general JavaScript) behavior of returning undefined with no error.

ignoreMemberNotFoundError: boolean;

Property Value

boolean

log

This is a callback delegate that will be called with debug information if non-null.

For example, you can set this to console.log.bind(console) to have it print debug information to the console, to help when troubleshooting host object usage.

By default this is null.

log: (...data: any[]) => void;

Property Value

(...data: any[]) => void

shouldPassTypedArraysAsArrays

By default, typed arrays are passed to the host as IDispatch. To instead pass typed arrays to the host as array, set this to true.

shouldPassTypedArraysAsArrays: boolean;

Property Value

boolean

shouldSerializeDates

By default this is false, and javascript Date objects will be sent to host objects as a string using JSON.stringify.

You can set this property to true to have Date objects properly serialize as a VT_DATE when sending to the native host object, and have VT_DATE properties and return values create a JavaScript Date object.

shouldSerializeDates: boolean;

Property Value

boolean