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();
|
await initSettings();
|
||||||
document.addEventListener("mouseup", handleMouseUp);
|
document.addEventListener("mouseup", handleMouseUp);
|
||||||
document.addEventListener("keydown", handleKeyDown);
|
document.addEventListener("keydown", handleKeyDown);
|
||||||
window.addEventListener("unload", onUnload, { once: true });
|
document.addEventListener("visibilitychange", handleVisibilityChange);
|
||||||
browser.storage.onChanged.addListener(handleSettingsChange);
|
browser.storage.onChanged.addListener(handleSettingsChange);
|
||||||
browser.runtime.onMessage.addListener(handleMessage);
|
browser.runtime.onMessage.addListener(handleMessage);
|
||||||
overWriteLogLevel();
|
overWriteLogLevel();
|
||||||
|
@ -133,8 +133,12 @@ const handleKeyDown = e => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onUnload = () => {
|
const handleVisibilityChange = () => {
|
||||||
browser.storage.onChanged.removeListener(handleSettingsChange);
|
if (document.visibilityState === "hidden") {
|
||||||
|
browser.storage.onChanged.removeListener(handleSettingsChange);
|
||||||
|
} else {
|
||||||
|
browser.storage.onChanged.addListener(handleSettingsChange);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let isEnabled = true;
|
let isEnabled = true;
|
||||||
|
|
Loading…
Reference in a new issue