Răsfoiți Sursa

cosmetics: reuse ERROR more

tophf 1 lună în urmă
părinte
comite
c67030b947

+ 1 - 1
src/background/utils/requests.js

@@ -94,7 +94,7 @@ function text2chunk(response, index, size) {
 
 /**
  * @param {GMReq.BG} req
- * @param {GMReq.EventTypeMap} events[]
+ * @param {GMReq.EventTypeMap[]} events
  * @param {boolean} blobbed
  * @param {boolean} chunked
  * @param {boolean} isJson

+ 1 - 1
src/common/ui/index.js

@@ -6,7 +6,7 @@ import Message from './message';
 import { VM_HOME } from '@/common/consts';
 
 /** Showing unexpected errors in UI so that the users can notify us */
-addEventListener('error', e => showUnhandledError(e.error));
+addEventListener(ERROR, e => showUnhandledError(e.error));
 addEventListener('unhandledrejection', e => showUnhandledError(e.reason));
 export function showUnhandledError(err) {
   if (!err) return;

+ 4 - 4
src/injected/content/inject.js

@@ -272,9 +272,9 @@ function inject(item, iframeCb) {
   const script = makeElem('script', !isCodeArray && code);
   // Firefox ignores sourceURL comment when a syntax error occurs so we'll print the name manually
   const onError = IS_FIREFOX && !iframeCb && (e => {
-    const { stack } = e.error;
+    const { stack } = e[ERROR];
     if (!stack || `${stack}`.includes(VM_UUID)) {
-      log('error', [item.displayName], e.error);
+      log(ERROR, [item.displayName], e[ERROR]);
       e.preventDefault();
     }
   });
@@ -306,14 +306,14 @@ function inject(item, iframeCb) {
     divRoot::appendChild(script);
   }
   if (onError) {
-    window::on('error', onError);
+    window::on(ERROR, onError);
   }
   if (!injectedRoot) {
     // When using declarativeContent there's no documentElement so we'll append to `document`
     (elemByTag('*') || document)::appendChild(div);
   }
   if (onError) {
-    window::off('error', onError);
+    window::off(ERROR, onError);
   }
   if (iframeCb) {
     injectedRoot = divRoot;

+ 1 - 1
src/injected/util/index.js

@@ -11,7 +11,7 @@ export {
 } from '@/common';
 export * from '@/common/consts';
 
-export const CONSOLE_METHODS = ['log', 'info', 'warn', 'error', 'debug'];
+export const CONSOLE_METHODS = ['log', 'info', 'warn', ERROR, 'debug'];
 
 export const fireBridgeEvent = (eventId, msg) => {
   const detail = cloneInto ? cloneInto(msg, document) : msg;

+ 1 - 1
src/injected/web/gm-values.js

@@ -99,7 +99,7 @@ function notifyChange(hooks, key, val, raw, oldRaw, remote = false) {
     try {
       fn(key, oldVal, newVal, remote);
     } catch (e) {
-      log('error', ['GM_addValueChangeListener', 'callback'], e);
+      log(ERROR, ['GM_addValueChangeListener', 'callback'], e);
     }
   });
 }

+ 2 - 2
src/injected/web/requests.js

@@ -8,11 +8,11 @@ const kResponse = 'response';
 const kResponseXML = 'responseXML';
 const kDocument = 'document';
 const kRaw = 'raw';
-const kOnerror = 'onerror';
+const kOnerror = 'on' + ERROR;
 const kOnload = 'onload';
 const EVENTS_TO_NOTIFY = [
   'abort',
-  'error',
+  ERROR,
   'load',
   'loadend',
   'loadstart',