From 3bf0f7e2f80249b472af34b9b50a9f7de0efd344 Mon Sep 17 00:00:00 2001 From: tophf Date: Tue, 5 Dec 2017 06:17:39 +0300 Subject: [PATCH] FF: ensure styles are ordered correctly in background tabs should probably help #284 --- content/apply.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/content/apply.js b/content/apply.js index e2f52124..31320aa7 100644 --- a/content/apply.js +++ b/content/apply.js @@ -386,6 +386,7 @@ let restorationCounter = 0; let observing = false; let sorting = false; + let timer; // allow any types of elements between ours, except for the following: const ORDERED_TAGS = ['head', 'body', 'style', 'link']; @@ -395,6 +396,10 @@ function init() { docRootObserver = new MutationObserver(sortStyleElements); Object.assign(docRootObserver, {start, stop}); + if (!chrome.app) { + // compensate for Firefox missing a step when loading the tab in background + setTimeout(sortStyleElements); + } } function start({sort = false} = {}) { if (sort && sortStyleMap()) { @@ -453,8 +458,8 @@ if (sorting) { sorting = false; docRootObserver.takeRecords(); - setTimeout(start); - //docRootObserver.start(); + clearTimeout(timer); + timer = setTimeout(start); } } function isMovable(el) {