let foo = "my result";
foo;tabs.executeScript() / notebook
tabs.executeScript()
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
function onExecuted(result) {
console.log(`We made it green`);
}
function onError(error) {
console.log(`Error: ${error}`);
}
const makeItGreen = 'document.body.style.border = "5px solid green"';
const executing = browser.tabs.executeScript({
code: makeItGreen,
});
executing.then(onExecuted, onError);function onExecuted(result) {
console.log(`We executed in all subframes`);
}
function onError(error) {
console.log(`Error: ${error}`);
}
const executing = browser.tabs.executeScript({
file: "/content-script.js",
allFrames: true,
});
executing.then(onExecuted, onError);function onExecuted(result) {
console.log(`We executed in tab 2`);
}
function onError(error) {
console.log(`Error: ${error}`);
}
const executing = browser.tabs.executeScript(2, {
file: "/content-script.js",
});
executing.then(onExecuted, onError);