Browse Source

fix: more reliable `nonce` workaround in FF

tophf 2 years ago
parent
commit
f7dc6cdc0f
1 changed files with 11 additions and 8 deletions
  1. 11 8
      src/background/utils/preinject.js

+ 11 - 8
src/background/utils/preinject.js

@@ -310,12 +310,10 @@ function onHeadersReceived(info) {
   const bag = cache.get(key);
   const bag = cache.get(key);
   // The INJECT data is normally already in cache if code and values aren't huge
   // The INJECT data is normally already in cache if code and values aren't huge
   if (bag && !bag[FORCE_CONTENT] && bag[INJECT]?.[SCRIPTS] && !skippedTabs[info.tabId]) {
   if (bag && !bag[FORCE_CONTENT] && bag[INJECT]?.[SCRIPTS] && !skippedTabs[info.tabId]) {
-    if (IS_FIREFOX && info.url.startsWith('https:')) {
-      detectStrictCsp(info, bag);
-    }
-    if (xhrInject) {
-      return prepareXhrBlob(info, bag);
-    }
+    const ffReg = IS_FIREFOX && info.url.startsWith('https:')
+      && detectStrictCsp(info, bag);
+    const res = xhrInject && prepareXhrBlob(info, bag);
+    return ffReg ? ffReg.then(res && (() => res)) : res;
   }
   }
 }
 }
 
 
@@ -587,8 +585,13 @@ function detectStrictCsp(info, bag) {
   } else {
   } else {
     return;
     return;
   }
   }
-  if (unregisterScriptFF(bag)) {
-    registerScriptDataFF(bag[INJECT], info.url);
+  m = unregisterScriptFF(bag);
+  if (m && !tmp) {
+    // Registering only without nonce, otherwise FF will incorrectly reuse it on tab reload
+    return Promise.all([
+      m,
+      registerScriptDataFF(bag[INJECT], info.url),
+    ]);
   }
   }
 }
 }