From be4fd17113b685d55bea96c421ef78590a739333 Mon Sep 17 00:00:00 2001 From: tophf Date: Sat, 24 Apr 2021 16:37:30 +0300 Subject: [PATCH] wait for just created script elements to load fixes #1233 --- js/polyfill.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/js/polyfill.js b/js/polyfill.js index f7435813..6d43aac7 100644 --- a/js/polyfill.js +++ b/js/polyfill.js @@ -69,6 +69,7 @@ //#region for our extension pages + const reqPromise = {}; window.require = async function require(urls, cb) { const promises = []; const all = []; @@ -83,13 +84,14 @@ if (!el) { el = document.createElement(tag); toLoad.push(el); - promises.push(new Promise((resolve, reject) => { + reqPromise[url] = new Promise((resolve, reject) => { el.onload = resolve; el.onerror = reject; el[attr] = url; if (isCss) el.rel = 'stylesheet'; - }).catch(console.warn)); + }).catch(console.warn); } + promises.push(reqPromise[url]); all.push(el); } if (toLoad.length) document.head.append(...toLoad);