From 36951432cf9be9f96792724a65f4f56ca70b498d Mon Sep 17 00:00:00 2001 From: saturn Date: Fri, 17 Jan 2020 19:19:13 -0600 Subject: [PATCH] Added workaround for Firefox performance bug --- src/contentScript.js | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) 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(); } /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/