DOMHandler interface

The DOMHandler interface is a base class for DOM-side scripts (typically in domSide.js). This means it does not have access to the runtime, since in Web Worker mode the runtime is hosted in a separate JavaScript context within the worker. However the DOM-side script does have access to the full DOM APIs, e.g. document, and using the messaging methods can communicate with the runtime. See runtime scripts for more information.

Methods

AddRuntimeMessageHandler(handler, callback)
AddRuntimeMessageHandlers(arr)
Add a callback to be run to handle a message posted from a runtime-side script. The handler is a string identifier. The callback receives the posted data as an argument. Note that if the caller in the runtime-side script originally used the PostToDOMAsync method, the callback may be an async function, and the return value is posted back to the runtime-side script. The AddRuntimeMessageHandlers variant accepts an array of [handler, callback] which is convenient when adding multiple handlers.
PostToRuntime(handler, data)
PostToRuntimeAsync(handler, data)
Post a message to a runtime-side script. The handler is a string identifier. The data must be structurally clonable (since it is posted down a MessageChannel). The async method returns a promise that resolves with the runtime-side callback's return value. The non-async method does not return a value and the runtime-side callback's return value is discarded (i.e. a "fire and forget" message).
Addon SDK Manual 2024-05-20

On this page