I have a color selection in an extension popup window, and I have the following code to save to localStorage upon windows close.
The window closes upon clicking “OK”, or “Cancel”:
window.addEventListener("unload", function(event) { //when the window is closed
localStorage.setItem("pickColor", "meep"); // save selected color to localStorage
let sending = browser.runtime.sendMessage({
message: "color set done"
});
console.log("message sent");
});
The message is sent, and the console.log fires, but saving to localStorage does not work, I get null
rather than my test value "meep"
, which indicates that the value is not being saved to localStorage.
I am using localStorage
rather than browser.storage.local
since this is used for only for the duration of the click.