The addModule()
method of the Worklet
interface loads the module in the given JavaScript file and adds it to the current Worklet
.
addModule(moduleURL)
addModule(moduleURL, options)
A Promise
that resolves once the module from the given URL has been added. The promise doesn't return any value.
If addModule()
fails, it rejects the promise, delivering one of the following errors to the rejection handler.
-
AbortError
-
The specified script is invalid or could not be loaded.
-
SyntaxError
-
The specified moduleURL
is invalid.
const audioCtx = new AudioContext();
const audioWorklet = audioCtx.audioWorklet;
audioWorklet.addModule('modules/bypassFilter.js', {
credentials: 'omit',
});
CSS.paintWorklet.addModule('https://mdn.github.io/houdini-examples/cssPaint/intro/worklets/hilite.js');
Once a paintWorklet
is included, the CSS image/paint()
function can be used to include the image created by the worklet:
@supports (background-image: paint(id)) {
h1 {
background-image: paint(hollowHighlights, filled, 3px);
}
}