Răsfoiți Sursa

fix: convert gmxhr url to string, use onerror

tophf 3 ani în urmă
părinte
comite
8169a818f6

+ 1 - 1
.eslintrc.js

@@ -2,7 +2,7 @@ const { readGlobalsFile } = require('./scripts/webpack-util');
 
 const FILES_INJECTED = [`src/injected/**/*.js`];
 const FILES_CONTENT = [
-  'src/injected/*.js',
+  'src/injected/index.js',
   'src/injected/content/**/*.js',
 ];
 const FILES_WEB = [`src/injected/web/**/*.js`];

+ 1 - 1
src/injected/content/safe-globals-content.js

@@ -46,7 +46,7 @@ export const getDetail = describeProperty(SafeCustomEvent[PROTO], 'detail').get;
 export const getRelatedTarget = describeProperty(SafeMouseEvent[PROTO], 'relatedTarget').get;
 export const getReadyState = describeProperty(Document[PROTO], 'readyState').get;
 export const isDocumentLoading = () => !/^(inter|compl)/::regexpTest(document::getReadyState());
-export const logging = createNullObj(console);
+export const logging = assign(createNullObj(), console);
 export const { chrome } = global;
 export const IS_FIREFOX = !chrome.app;
 export const VM_UUID = chrome.runtime.getURL('');

+ 17 - 3
src/injected/web/requests.js

@@ -10,7 +10,22 @@ bridge.addHandlers({
 });
 
 export function onRequestCreate(opts, context, fileName) {
-  if (!opts.url) throw new SafeError('Required parameter "url" is missing.');
+  opts = createNullObj(opts);
+  let { url } = opts;
+  if (url && !isString(url)) { // USVString in XMLHttpRequest spec calls ToString
+    try {
+      url = url::URLToString();
+    } catch (e) {
+      url = getOwnProp(url, 'href'); // `location`
+    }
+    opts.url = url;
+  }
+  if (!url) {
+    const err = new SafeError('Required parameter "url" is missing.');
+    const { onerror } = opts;
+    if (isFunction(onerror)) onerror(err);
+    else throw err;
+  }
   const scriptId = context.id;
   const id = safeGetUniqId('VMxhr');
   const req = {
@@ -94,8 +109,7 @@ function callback(req, msg) {
 }
 
 function start(req, context, fileName) {
-  const { id, scriptId } = req;
-  const opts = createNullObj(req.opts);
+  const { id, opts, scriptId } = req;
   // withCredentials is for GM4 compatibility and used only if `anonymous` is not set,
   // it's true by default per the standard/historical behavior of gmxhr
   const { data, withCredentials = true, anonymous = !withCredentials } = opts;