From fbf73a236810e99a0e8ca50b243f1e3832acd7e7 Mon Sep 17 00:00:00 2001 From: tophf Date: Mon, 24 Feb 2020 16:45:47 +0300 Subject: [PATCH] fixup! init main frame first --- popup/popup.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/popup/popup.js b/popup/popup.js index 74d94156..d200aeb3 100644 --- a/popup/popup.js +++ b/popup/popup.js @@ -26,8 +26,8 @@ initTabUrls() Promise.all([ onDOMready().then(() => initPopup(frames)), ...frames - .filter(f => !f.isDupe) - .map(({url}) => url && API.getStylesByUrl(url).then(styles => ({styles, url}))), + .filter(f => f.url && !f.isDupe) + .map(({url}) => API.getStylesByUrl(url).then(styles => ({styles, url}))), ])) .then(([, ...results]) => { if (results[0]) { @@ -204,11 +204,12 @@ function initPopup(frames) { /** @param {chrome.webNavigation.GetAllFrameResultDetails[]} frames */ function sortTabFrames(frames) { const unknown = new Map(frames.map(f => [f.frameId, f])); - const known = new Map([[0, {frameId: 0}]]); - let lastSize = -1; - while (unknown.size && unknown.size !== lastSize) { + const known = new Map([[0, unknown.get(0) || {frameId: 0, url: ''}]]); + unknown.delete(0); + let lastSize = 0; + while (unknown.size !== lastSize) { for (const [frameId, f] of unknown) { - if (known.has(f.parentFrameId) || f.parentFrameId < 0) { + if (known.has(f.parentFrameId)) { known.set(frameId, f); unknown.delete(frameId); if (f.url === ABOUT_BLANK) f.url = known.get(f.parentFrameId).url; @@ -219,7 +220,7 @@ function sortTabFrames(frames) { const sortedFrames = [...known.values(), ...unknown.values()]; const urls = new Set([ABOUT_BLANK]); for (const f of sortedFrames) { - f.url = f.url || ''; + if (!f.url) f.url = ''; f.isDupe = urls.has(f.url); urls.add(f.url); }