function onRemoved() {
console.log(`Removed window`);
}
function onError(error) {
console.error(`Error:`, error);
}
browser.browserAction.onClicked.addListener((tab) => {
let removing = browser.windows.remove(tab.windowId);
removing.then(onRemoved, onError);
});windows.remove() / notebook
windows.remove()
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
// in a script loaded by the page in the window
document.querySelector("#close").addEventListener(async ({ button }) => {
try {
if (button) return; // not a left click
const windowId = (await browser.windows.getCurrent()).id;
await browser.windows.remove(windowId);
// this point will never be reached, since the window is gone
} catch (error) {
console.error("Closing failed:", error);
}
});