Replace unload event with visibilitychange (#480)
This should fix bfcache compatibility issues. https://developer.mozilla.org/en-US/docs/Web/API/Window/unload_event#usage_notes
This commit is contained in:
parent
6af6abd501
commit
bb372420d7
|
@ -9,7 +9,7 @@ const init = async () => {
|
|||
await initSettings();
|
||||
document.addEventListener("mouseup", handleMouseUp);
|
||||
document.addEventListener("keydown", handleKeyDown);
|
||||
window.addEventListener("unload", onUnload, { once: true });
|
||||
document.addEventListener("visibilitychange", handleVisibilityChange);
|
||||
browser.storage.onChanged.addListener(handleSettingsChange);
|
||||
browser.runtime.onMessage.addListener(handleMessage);
|
||||
overWriteLogLevel();
|
||||
|
@ -133,8 +133,12 @@ const handleKeyDown = e => {
|
|||
}
|
||||
};
|
||||
|
||||
const onUnload = () => {
|
||||
const handleVisibilityChange = () => {
|
||||
if (document.visibilityState === "hidden") {
|
||||
browser.storage.onChanged.removeListener(handleSettingsChange);
|
||||
} else {
|
||||
browser.storage.onChanged.addListener(handleSettingsChange);
|
||||
}
|
||||
};
|
||||
|
||||
let isEnabled = true;
|
||||
|
|
Loading…
Reference in a new issue