Use a poll to catch extra tricky location changes
HEAD master1 files changed, 9 insertions, 10 deletions
diff --git a/extension/interactive-bgm.js b/extension/interactive-bgm.js
index 2bafe54..9c0e5dd 100644
--- a/extension/interactive-bgm.js
+++ b/extension/interactive-bgm.js
@@ -1,18 +1,17 @@
const sendURL = () => {
- browser.runtime.sendMessage({urlString: location.toString()});
+ if (!document.hidden) {
+ browser.runtime.sendMessage({urlString: location.toString()});
+ }
};
window.addEventListener('focus', sendURL);
+window.addEventListener('popstate', sendURL);
+document.addEventListener('visibilitychange', sendURL);
+sendURL();
-document.addEventListener('visibilitychange', () => {
- if (!document.hidden) {
- sendURL();
- }
-});
-
-if (!document.hidden) {
- sendURL();
-}
+// Some things we just can't reliably detect through event, like the location being changed via JS.
+// To catch those, we poll regularly.
+setInterval(sendURL, 1000);
let isShowingCreateTrack = false;
|