files/en-us/web/api/worklet/addmodule/index.md
{{APIRef("Worklets")}}{{SecureContext_Header}}
The addModule() method of the
{{domxref("Worklet")}} interface loads the module in the given JavaScript file and
adds it to the current Worklet.
addModule(moduleURL)
addModule(moduleURL, options)
moduleURL
options {{optional_inline}}
credentials
"omit",
"same-origin", or "include". Defaults to
"same-origin". See also {{domxref("Request.credentials")}}.A {{jsxref("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 {{domxref("DOMException")}}
SyntaxError {{domxref("DOMException")}}
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 the script has been added to the paint worklet, the CSS {{cssxref("image/paint", "paint()")}} function can be used to include the image created by the worklet:
@supports (background-image: paint(id)) {
h1 {
background-image: paint(hollow-highlights, filled, 3px);
}
}
{{Specifications}}
{{Compat}}