I am coding my first extension right now and I wanted to save a value before the browser closes. I, at first, tried to use browser.runtime.onSuspend.addListener() :
browser.runtime.onSuspend.addListener(() => {
window.localStorage.setItem("suspent", Date.now());
});
This did not work. I googled for a bit found that one could also use window.addEventListener(‘unload’, function):
window.addEventListener('unload', function () {
window.localStorage.setItem("unload", Date.now());
});
This version worked without any issues.
Does anybody know why the first one using onSuspend didn’t work?