这是
实验性技术
检查
浏览器兼容性表格
要小心谨慎在生产中使用这之前。
addModule()
方法在
Worklet
interface loads the module in the given JavaScript file and adds it to the current
Worklet
.
addPromise = worklet.addModule(moduleURL); addPromise = worklet.addModule(moduleURL, options);
moduleURL
字符串
containing the URL of a JavaScript file with the module to add.
选项
可选
credentials
: A
RequestCredentials
value that indicates whether to send credentials (e.g. cookies and HTTP authentification) when loading the module. Can be one of
"omit"
,
"same-origin"
,或
"include"
。默认为
"same-origin"
。另请参阅
Request.credentials
.
A
Promise
that resolves once the module from the given URL has been added. The promise doesn't return any value.
若
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
moduleURL
无效。
const audioCtx = new AudioContext();
const audioWorklet = audioCtx.audioWorklet;
await audioWorklet.addModule('modules/bypassFilter.js', {
credentials: 'omit',
});
CSS.paintWorklet.addModule('https://mdn.github.io/houdini-examples/cssPaint/intro/worklets/hilite.js');
一旦
paintWorklet
is included, the CSS
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);
}
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
Worklets Level 1
The definition of 'addModule()' in that specification. |
工作草案 |
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
更新 GitHub 上的兼容性数据| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
addModule
|
Chrome 65 | Edge 79 |
Firefox
No
Disabled
|
IE No | Opera 52 | Safari No | WebView Android 65 | Chrome Android 65 |
Firefox Android
No
Disabled
|
Opera Android 47 | Safari iOS No | Samsung Internet Android 9.0 |
完整支持
不支持
实验。期望将来行为有所改变。
见实现注意事项。
用户必须明确启用此特征。
Worklet
addModule()