Files
discord-decomp/_bundle/instrumentXHR.js
T
2026-11-01 12:12:55 +02:00

103 lines
3.2 KiB
JavaScript

// Metro module 1068 (f1069).
import { timestampInSeconds, isString, triggerHandlers, addHandler, maybeInstrument } from "./Module817";
import { WINDOW } from "./Module1039";
let c879_3;
const instrumentXHR = function instrumentXHR() {
if (WINDOW.XMLHttpRequest) {
const prototype = XMLHttpRequest.prototype;
prototype.open = new Proxy(prototype.open, {
apply: (a0, a1, a2) => {
let onreadystatechangeHandler2;
const xhr = a1;
const virtualError = new Error();
const startTimestamp = 1000 * timestampInSeconds();
const method = isString(a2[0]) ? a2[0].toUpperCase() : void 0;
const url = (function parseXhrUrlArg(a0) {
let r10;
if (isString(a0)) {
return a0;
}
try {
r10 = a0.toString();
} catch ($e) {
return void 0;
}
return r10;
})(a2[1]);
if (method && url) {
a1[c879_3] = {
method,
url,
request_headers: {}
};
if (method === "POST" && url.match(/sentry_key/)) {
a1.__sentry_own_request__ = true;
}
onreadystatechangeHandler2 = () => {
const r2 = xhr[c879_3];
if (r2 && xhr.readyState === 4) {
try {
r2.status_code = xhr.status;
} catch ($e) {}
triggerHandlers("xhr", {
endTimestamp: 1000 * timestampInSeconds(),
startTimestamp,
xhr,
virtualError
});
}
};
if ("onreadystatechange" in a1 && typeof a1.onreadystatechange === "function") {
a1.onreadystatechange = new Proxy(a1.onreadystatechange, {
apply: (a0, a1, a2) => {
onreadystatechangeHandler2();
return a0.apply(a1, a2);
}
});
} else {
a1.addEventListener("readystatechange", onreadystatechangeHandler2);
}
a1.setRequestHeader = new Proxy(a1.setRequestHeader, {
apply: (a0, a1, a2) => {
const [r7, r6] = a2;
const r13 = a1[c879_3];
if (r13 && isString(r7) && isString(r6)) {
r13.request_headers[r7.toLowerCase()] = r6;
}
return a0.apply(a1, a2);
}
});
return a0.apply(a1, a2);
}
return a0.apply(a1, a2);
}
});
prototype.send = new Proxy(prototype.send, {
apply: (a0, a1, a2) => {
const r7 = a1[c879_3];
if (r7) {
if (a2[0] !== void 0) {
r7.body = a2[0];
}
triggerHandlers("xhr", {
startTimestamp: 1000 * timestampInSeconds(),
xhr: a1
});
return a0.apply(a1, a2);
}
return a0.apply(a1, a2);
}
});
}
};
Object.defineProperty(exports, Symbol.toStringTag, {
value: "Module"
});
c879_3 = "__sentry_xhr_v3__";
export const SENTRY_XHR_DATA_KEY = "__sentry_xhr_v3__";
export function addXhrInstrumentationHandler(a0) {
addHandler("xhr", a0);
maybeInstrument("xhr", instrumentXHR);
}
export { instrumentXHR };