// background.js
function foo() {
console.log("I'm defined in background.js");
}runtime.getBackgroundPage() / notebook
runtime.getBackgroundPage()
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
// popup.js
function onGot(page) {
page.foo();
}
function onError(error) {
console.log(`Error: ${error}`);
}
let getting = browser.runtime.getBackgroundPage();
getting.then(onGot, onError);