- Introduced a new script (inject.js) to override the fetch and XMLHttpRequest methods to capture requests to the "getgeoidx" endpoint. - Captured request body and URL, and sent the data to the extension via postMessage. - Added intercept.js to inject the new script into the page and listen for messages to forward captured data to the extension.
39 lines
1.5 KiB
JavaScript
39 lines
1.5 KiB
JavaScript
(function() {
|
|
const origFetch = window.fetch;
|
|
window.fetch = async function(input, init = {}) {
|
|
const url = typeof input === "string" ? input : input.url;
|
|
if (url.endsWith("getgeoidx")) {
|
|
let body = init.body || null;
|
|
if (body instanceof ArrayBuffer) {
|
|
body = new TextDecoder().decode(new Uint8Array(body));
|
|
} else if (body instanceof Blob) {
|
|
body = await new Response(body).text();
|
|
} else if (body != null && typeof body !== "string") {
|
|
try { body = JSON.stringify(body); } catch(e) { body = String(body); }
|
|
}
|
|
window.postMessage({ type: "ZMS_CAPTURE", url, body }, "*");
|
|
}
|
|
return origFetch.apply(this, arguments);
|
|
};
|
|
|
|
// patch XMLHttpRequest to catch getgeoidx
|
|
const origOpen = XMLHttpRequest.prototype.open;
|
|
const origSend = XMLHttpRequest.prototype.send;
|
|
XMLHttpRequest.prototype.open = function(method, url, ...rest) {
|
|
this._zms_url = url;
|
|
return origOpen.call(this, method, url, ...rest);
|
|
};
|
|
XMLHttpRequest.prototype.send = function(body) {
|
|
if (this._zms_url && this._zms_url.endsWith("getgeoidx")) {
|
|
let captured = body;
|
|
if (body instanceof ArrayBuffer) {
|
|
captured = new TextDecoder().decode(new Uint8Array(body));
|
|
} else if (body != null && typeof body !== "string") {
|
|
try { captured = JSON.stringify(body); } catch(e) { captured = String(body); }
|
|
}
|
|
window.postMessage({ type: "ZMS_CAPTURE", url: this._zms_url, body: captured }, "*");
|
|
}
|
|
return origSend.call(this, body);
|
|
};
|
|
})();
|