Add request interception for getgeoidx API calls

- 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.
This commit is contained in:
2025-06-05 11:32:35 +02:00
parent 69fc5bcd12
commit 1e002d5bd7
4 changed files with 193 additions and 191 deletions

38
js/inject.js Normal file
View File

@@ -0,0 +1,38 @@
(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);
};
})();