diff --git a/src/contentScript.js b/src/contentScript.js index 0a3e34d..98f4f9d 100644 --- a/src/contentScript.js +++ b/src/contentScript.js @@ -166,20 +166,30 @@ function restoreScrollability() { */ function startConstantVigilance() { // console.log("startConstantVigilance"); - var observer = new MutationObserver((mutationsList, observer) => { + var observer; + var starter = function() { + observer.observe(document.querySelector("html"), { + attributes: true, + childList: true, + subtree: true + }); + }; + + observer = new MutationObserver((mutationsList, observer) => { + // Workaround for Firefox performance bug. Firefox does not properly + // coalesce mutations into the mutationsList, instead calling the + // callback potentially thousands of times. Therefore we must + // disconnect the observer, wait for the main thread to become idle, + // and then restart it. + observer.disconnect(); window.requestIdleCallback(() => { - for (var mutation of mutationsList) { - killSticky(mutation.target); - } + killSticky(); + starter(); }); }); console.log("Commencing vigilance for stickies!"); - observer.observe(document.querySelector("html"), { - attributes: true, - childList: true, - subtree: true - }); + starter(); } /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/