Skip to content

Commit

Permalink
Implemented handling Request object.
Browse files Browse the repository at this point in the history
  • Loading branch information
acsbendi committed Dec 13, 2023
1 parent 770cef6 commit a3647af
Showing 1 changed file with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,25 @@ XMLHttpRequest.prototype.send = function (body) {
window._fetch = window.fetch;
window.fetch = function () {
const url = arguments[0];
const firstArgument = arguments[0];
let url;
let method;
let body;
let headers;
if (typeof firstArgument === 'string') {
url = firstArgument;
method = arguments[1] && 'method' in arguments[1] ? arguments[1]['method'] : "GET";
body = arguments[1] && 'body' in arguments[1] ? arguments[1]['body'] : "";
headers = JSON.stringify(arguments[1] && 'headers' in arguments[1] ? arguments[1]['headers'] : {});
} else {
// Request object
url = firstArgument.url;
method = firstArgument.method;
body = firstArgument.body;
headers = JSON.stringify(Object.fromEntries(firstArgument.headers.entries()));
}
const fullUrl = getFullUrl(url);
const method = arguments[1] && 'method' in arguments[1] ? arguments[1]['method'] : "GET";
const body = arguments[1] && 'body' in arguments[1] ? arguments[1]['body'] : "";
const headers = JSON.stringify(arguments[1] && 'headers' in arguments[1] ? arguments[1]['headers'] : {});
let err = new Error();
const err = new Error();
$INTERFACE_NAME.recordFetch(fullUrl, method, body, headers, err.stack);
return window._fetch.apply(this, arguments);
}
Expand Down

0 comments on commit a3647af

Please sign in to comment.