AddHostObjectToScript Sample
The following buttons interact with the chrome.webview.hostObjects.sample
object. Open DevTools console to try running whatever code you like on this object.
Get Property
Get property async
Runs await chrome.webview.hostObjects.sample.property
Get property sync
Runs chrome.webview.hostObjects.sync.sample.property
Set Property
Set property async
Runs chrome.webview.hostObjects.sample.property = value
which doesn't wait for the property to be set and returns immediately.
Set property explicit async
Runs await chrome.webview.hostObjects.sample.setHostProperty("property", value)
which waits for the property to be set.
Set property sync
Runs chrome.webview.hostObjects.sync.sample.property = value
Indexed Property
Get indexed property async
Runs await chrome.webview.hostObjects.sample.indexedProperty[paramValue]
Set indexed property async
Runs chrome.webview.hostObjects.sync.sample.indexedProperty[paramValue1] = paramValue2
Invoke Method
Invoke method async
Runs await chrome.webview.hostObjects.sample.MethodWithParametersAndReturnValue(paramValue1, paramValue2)
Invoke method sync
Runs chrome.webview.hostObjects.sync.sample.MethodWithParametersAndReturnValue(paramValue1, paramValue2)
Invoke Callback
Invoke Callback
Runs chrome.webview.hostObjects.sample.CallCallbackAsynchronously(() => { /* ... */ })
Date Objects
Set Date to Now
Sets chrome.webview.hostObjects.options.shouldSerializeDates = true
and then runs chrome.webview.hostObjects.sample.dateProperty = new Date()
Set Remote Date
Calls chrome.webview.hostObjects.sample.createNativeDate()
to have the native object create and set the current time to the DateProperty
IFrame