async function setOnActiveWindow() {
let currentWindow = await browser.windows.getLastFocused();
await browser.sessions.setWindowValue(currentWindow.id, "my-key", "my-value");
}
async function removeFromActiveWindow() {
let currentWindow = await browser.windows.getLastFocused();
await browser.sessions.removeWindowValue(currentWindow.id, "my-key");
}
browser.menus.create({
id: "add-my-item",
title: "add item",
contexts: ["all"],
});
browser.menus.create({
id: "remove-my-item",
title: "remove item",
contexts: ["all"],
});
browser.menus.onClicked.addListener((info) => {
if (info.menuItemId === "add-my-item") {
setOnActiveWindow();
} else {
removeFromActiveWindow();
}
});sessions.removeWindowValue() / notebook
sessions.removeWindowValue()
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.