(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); }; })();