const defaultHosts = "*://*.org/*";
const defaultCode =
"document.body.innerHTML = '<h1>This page has been eaten<h1>'";
async function register(hosts, code) {
return await browser.contentScripts.register({
matches: [hosts],
js: [{ code }],
runAt: "document_idle",
});
}
let registered = register(defaultHosts, defaultCode);contentScripts.register() / notebook
contentScripts.register()
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
const scriptObj = await browser.contentScripts.register({
js: [{ file: "/content_scripts/example.js" }],
matches: ["<all_urls>"],
allFrames: true,
runAt: "document_start",
});