1
0
Эх сурвалжийг харах

feat: remind users to reload tab if browser API fails

tophf 4 жил өмнө
parent
commit
e278cfc7c1
1 өөрчлөгдсөн 13 нэмэгдсэн , 1 устгасан
  1. 13 1
      src/common/browser.js

+ 13 - 1
src/common/browser.js

@@ -70,7 +70,19 @@ if (!IS_FIREFOX && !global.browser?.runtime) {
           reject(stackInfo);
         }
       };
-      func::apply(thisArg, args);
+      if (process.env.IS_INJECTED) {
+        try {
+          func::apply(thisArg, args);
+        } catch (e) {
+          if (e[MESSAGE] === 'Extension context invalidated.') {
+            console.error('Please reload the tab to restore Violentmonkey API for userscripts.');
+          } else {
+            throw e;
+          }
+        }
+      } else {
+        func::apply(thisArg, args);
+      }
       if (process.env.DEBUG) promise.catch(err => console.warn(args, err?.[MESSAGE] || err));
       return promise;
     }