Worklet Class

A worklet (https://html.spec.whatwg.org/multipage/worklets.html#worklets-worklet): the module scripts added with Worklet.AddModule run in each of its global scopes (WorkletGlobalScope), which have no access to the DOM. A worklet belongs to a document (e.g. CSS.paintWorklet, Document.PaintWorklet).

public abstract class Worklet

Remarks

The global scopes of a worklet are realms of the script engine of the document (BrowsingContextOptions.ScriptEngine): their scripts and their callbacks run on the thread of the event loop of the document, never concurrently with the scripts of the document. The global scopes are created by the first call of Worklet.AddModule, and are terminated when the document is destroyed.

See also

Methods

NameDescription
AddModule(string, WorkletOptions?)Loads a module script and runs it in the global scopes of the worklet (https://html.spec.whatwg.org/multipage/worklets.html#dom-worklet-addmodule). The module and its imports are fetched once for the worklet, with the document as the client of the requests (its content security policies, its referrer policy, its service worker...), as CORS requests.

AddModule(string, WorkletOptions?)

Worklet.cs

Loads a module script and runs it in the global scopes of the worklet (https://html.spec.whatwg.org/multipage/worklets.html#dom-worklet-addmodule). The module and its imports are fetched once for the worklet, with the document as the client of the requests (its content security policies, its referrer policy, its service worker...), as CORS requests.

public Task AddModule(string moduleUrl, WorkletOptions? options = null)

Parameters

moduleUrl string
The URL of the module script, relative to the base URL of the document.
options WorkletOptions?
The options: the credentials mode of the requests.

Returns

Task A task completed when the module ran in every global scope. It fails with a DomException: a SyntaxError when the URL is invalid, an AbortError when a module cannot be fetched (or when the scripts cannot run: no script engine, a document that is not a secure context or that is destroyed); or with the error of a module that cannot be parsed or linked.

See also