// background.js
function foo() {
console.log("I'm defined in background.js");
}extension.getBackgroundPage() / notebook
extension.getBackgroundPage()
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
// popup.js
let page = browser.extension.getBackgroundPage();
page.foo(); // -> "I'm defined in background.js"