Skip to content

Commit a3647af

Browse files
committed
Implemented handling Request object.
1 parent 770cef6 commit a3647af

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

app/src/main/java/com/acsbendi/requestinspectorwebview/RequestInspectorJavaScriptInterface.kt

+18-5
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,25 @@ XMLHttpRequest.prototype.send = function (body) {
299299
300300
window._fetch = window.fetch;
301301
window.fetch = function () {
302-
const url = arguments[0];
302+
const firstArgument = arguments[0];
303+
let url;
304+
let method;
305+
let body;
306+
let headers;
307+
if (typeof firstArgument === 'string') {
308+
url = firstArgument;
309+
method = arguments[1] && 'method' in arguments[1] ? arguments[1]['method'] : "GET";
310+
body = arguments[1] && 'body' in arguments[1] ? arguments[1]['body'] : "";
311+
headers = JSON.stringify(arguments[1] && 'headers' in arguments[1] ? arguments[1]['headers'] : {});
312+
} else {
313+
// Request object
314+
url = firstArgument.url;
315+
method = firstArgument.method;
316+
body = firstArgument.body;
317+
headers = JSON.stringify(Object.fromEntries(firstArgument.headers.entries()));
318+
}
303319
const fullUrl = getFullUrl(url);
304-
const method = arguments[1] && 'method' in arguments[1] ? arguments[1]['method'] : "GET";
305-
const body = arguments[1] && 'body' in arguments[1] ? arguments[1]['body'] : "";
306-
const headers = JSON.stringify(arguments[1] && 'headers' in arguments[1] ? arguments[1]['headers'] : {});
307-
let err = new Error();
320+
const err = new Error();
308321
$INTERFACE_NAME.recordFetch(fullUrl, method, body, headers, err.stack);
309322
return window._fetch.apply(this, arguments);
310323
}

0 commit comments

Comments
 (0)