Creating View Extensions
Use DOMScripts to display custom UI using HTML/DOM.
Normally, extension code runs in a headless JSContext. This code has access to Bike-specific APIs, but cannot use HTML/DOM. To display custom UI your extension installs a DOMScript into a WebView that's hosted by Bike.
If you’ve used Web Workers, the architecture will feel familiar: both run in isolated script contexts and communicate with the originating context using postMessage
and onmessage
.
DOMScripts are loaded by name and must be located in the src/dom
folder of your extension. Bike API's that allow you to install DOMScripts include window.presentSheet
and window.inspector.addItem
.
DOMScripts Summary:
Used to display UI using HTML/DOM.
Do not have access to standard extension APIs.
Run in a separate context from standard extension code.
Must be located in the extension's
src/dom
folder and loaded by name.Communicate with extension code via
postMessage
andonmessage
.For security network access is disabled for DOMScripts. To display network accessed information the originating extension should perform a fetch and the
postMessage
to results to the DOMScript.
Getting Started
To install a DOMScript:
Create a dom script in
/src/dom/<scriptname>
.Add the
domScript
permission to your extension'smanifest.json
.Pass the DOMScriptName to a Bike's API such as
window.inspector.addItem
.Use the returned handle to communicate with the DOMScript using
onmessage
andpostMessage
.
Example
First lets modify our manifest.json
so that our extension is allowed to install DOMScripts.
Next create a new DOMScript at src/dom/inspector_item.ts
. Note, DOMScript must always be placed in the top level of the src/dom
subfolder.
Finally add the following code to your extensions main.ts
file. This extension code adds our DOMScript to each window's inspector. Once the DOMScript has loaded our extension posts a message to the script.
Last updated