From 50959354ec3538dbf39c8c0abaf275e3382de6f3 Mon Sep 17 00:00:00 2001 From: tophf Date: Fri, 5 Feb 2021 10:35:02 +0300 Subject: [PATCH] wait for next paint in about:blank frames, fixes #1165 --- content/apply.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/content/apply.js b/content/apply.js index 786b4948..013f4816 100644 --- a/content/apply.js +++ b/content/apply.js @@ -65,11 +65,15 @@ } else { const SYM_ID = 'styles'; const SYM = Symbol.for(SYM_ID); + const parentStyles = isFrameAboutBlank && + tryCatch(() => parent[parent.Symbol.for(SYM_ID)]); const styles = window[SYM] || - (isFrameAboutBlank - ? tryCatch(() => parent[parent.Symbol.for(SYM_ID)]) - : chrome.app && !chrome.tabs && tryCatch(getStylesViaXhr)) || + /* about:blank iframes are often used by sites for file upload or background tasks + * and they may break if unexpected DOM stuff is present at `load` event + * so we'll add the styles in the next tick */ + parentStyles && await new Promise(requestAnimationFrame) && parentStyles || + chrome.app && !chrome.tabs && tryCatch(getStylesViaXhr) || await API.styles.getSectionsByUrl(matchUrl, null, true); hasStyles = !styles.disableAll; if (hasStyles) {