Skip to content

Commit

Permalink
Merge pull request #2792 from ToadKing/fix-xhr
Browse files Browse the repository at this point in the history
fix XMLHttpRequests that don't have the "async" parameter

Refs #2771
  • Loading branch information
arantius committed Jan 8, 2018
2 parents aaadd6f + 1932318 commit c341a10
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions src/user-script-obj.js
Expand Up @@ -9,7 +9,7 @@ reference any other objects from this file.
// Increment this number when updating `calculateEvalContent()`. If it
// is higher than it was when eval content was last calculated, it will
// be re-calculated.
const EVAL_CONTENT_VERSION = 7;
const EVAL_CONTENT_VERSION = 9;


// Private implementation.
Expand All @@ -19,20 +19,17 @@ const extensionVersion = chrome.runtime.getManifest().version;
const aboutBlankRegexp = /^about:blank/;

const SCRIPT_ENV_EXTRA = `
(() => {
let origXhr = XMLHttpRequest;
XMLHttpRequest = new Proxy(XMLHttpRequest, {
construct: (target, argumentsList, newTarget) => {
let xhr = new origXhr();
let origOpen = xhr.open;
xhr.open = (method_, url_, async_, user_, password_) => {
let url = new URL(url_, document.baseURI);
return origOpen.apply(xhr, [method_, url.toString(), async_, user_, password_]);
};
return xhr;
},
});
})();
{
let origOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function open(method, url) {
// only include method and url parameters so the function length is set properly
if (arguments.length >= 2) {
let newUrl = new URL(arguments[1], document.location.href);
arguments[1] = newUrl.toString();
}
return origOpen.apply(this, arguments);
};
}
`;


Expand Down

0 comments on commit c341a10

Please sign in to comment.