FF: ensure styles are ordered correctly in background tabs

should probably help #284
This commit is contained in:
tophf 2017-12-05 06:17:39 +03:00
parent 3e34c77625
commit 3bf0f7e2f8

View File

@ -386,6 +386,7 @@
let restorationCounter = 0; let restorationCounter = 0;
let observing = false; let observing = false;
let sorting = false; let sorting = false;
let timer;
// allow any types of elements between ours, except for the following: // allow any types of elements between ours, except for the following:
const ORDERED_TAGS = ['head', 'body', 'style', 'link']; const ORDERED_TAGS = ['head', 'body', 'style', 'link'];
@ -395,6 +396,10 @@
function init() { function init() {
docRootObserver = new MutationObserver(sortStyleElements); docRootObserver = new MutationObserver(sortStyleElements);
Object.assign(docRootObserver, {start, stop}); 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} = {}) { function start({sort = false} = {}) {
if (sort && sortStyleMap()) { if (sort && sortStyleMap()) {
@ -453,8 +458,8 @@
if (sorting) { if (sorting) {
sorting = false; sorting = false;
docRootObserver.takeRecords(); docRootObserver.takeRecords();
setTimeout(start); clearTimeout(timer);
//docRootObserver.start(); timer = setTimeout(start);
} }
} }
function isMovable(el) { function isMovable(el) {