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

479 lines
17 KiB
JavaScript

// Metro module 1058 (f1059).
import { msToSec, startAndEndSpan, getBrowserPerformanceAPI, isMeasurementValue } from "./Module1059";
import { stringMatchesSomePattern, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, isPrimitive, parseUrl, browserPerformanceTimeOrigin, spanToJSON, setMeasurement, htmlTreeAsString, getActiveSpan, getComponentName } from "./Module817";
import { WINDOW } from "./Module1039";
import { trackLcpAsStandaloneSpan } from "./Module1061";
import { trackClsAsStandaloneSpan } from "./Module1062";
import { addPerformanceInstrumentationHandler, addLcpInstrumentationHandler, addTtfbInstrumentationHandler, addClsInstrumentationHandler } from "./triggerHandlers";
import { getVisibilityWatcher } from "./onVisibilityUpdate";
import { getActivationStart } from "./Module1042";
import { getNavigationEntry } from "./Module1043";
import { resourceTimingToSpanAttributes } from "./Module1063";
import { HermesBuiltin } from "../_hermes/prelude";
function $mk67609($env) {
return (a0) => {
const [r15, r16] = a0;
const r18 = $env;
const r20 = r18[0][r15];
if (r20 != null && ((typeof r20 === "number" ? r20 < 2147483647 : typeof r20 === "number") || typeof r20 === "string")) {
r18[1][r16] = r20;
}
};
}
let c869_3, c869_4, c869_5, c869_6, _addNavigationSpans, _addPerformanceNavigationTiming, _addResourceSpans;
const _addMeasureSpans = function _addMeasureSpans(a0, a1, a2, a3, a4, ignorePerformanceApiSpans) {
L9: {
if (!(function isReact19MeasureEntry(a0) {
let track;
if (a0?.entryType === "measure") {
try {
track = a0.detail.devtools.track;
} catch ($e) {
return void 0;
}
return track === "Components ⚛";
}
})(a1)) {
if (["mark", "measure"].includes(a1.entryType) && stringMatchesSomePattern(a1.name, ignorePerformanceApiSpans)) {
break L9;
}
const navigationEntry = getNavigationEntry(false);
const r41 = a4 + Math.max(a2, msToSec(navigationEntry ? navigationEntry.requestStart : 0));
const r42 = a4 + a2;
const r43 = r42 + a3;
const attributes = {};
attributes[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] = "auto.resource.browser.metrics";
if (r41 !== r42) {
attributes["sentry.browser.measure_happened_before_request"] = true;
attributes["sentry.browser.measure_start_time"] = r41;
}
(function _addDetailToSpanAttributes(a0, a1) {
L20: {
L22: {
L9: {
try {
const detail = a1.detail;
if (detail) {
if (typeof detail !== "object") {
if (isPrimitive(detail)) {
a0["sentry.browser.measure.detail"] = detail;
break L9;
}
try {
a0["sentry.browser.measure.detail"] = JSON.stringify(detail);
break L22;
} catch ($e) {
break L22;
}
}
for (const item of Object.entries(detail)) {
const [r53, r54] = item;
if (r54 && isPrimitive(r54)) {
a0[`sentry.browser.measure.detail.${r53}`] = r54;
continue;
}
if (r54 !== void 0) {
try {
a0[`sentry.browser.measure.detail.${r53}`] = JSON.stringify(r54);
} catch ($e) {}
}
}
break L20;
}
} catch ($e) {
break L22;
}
return void 0;
}
return void 0;
}
return void 0;
}
})(attributes, a1);
if (r41 <= r43) {
startAndEndSpan(a0, r41, r43, {
name: a1.name,
op: a1.entryType,
attributes
});
}
}
}
};
_addNavigationSpans = function _addNavigationSpans(a0, a1, a2) {
["unloadEvent", "redirect", "domContentLoadedEvent", "loadEvent", "connect"].forEach((item) => {
_addPerformanceNavigationTiming(a0, a1, item, a2);
});
_addPerformanceNavigationTiming(a0, a1, "secureConnection", a2, "TLS/SSL");
_addPerformanceNavigationTiming(a0, a1, "fetch", a2, "cache");
_addPerformanceNavigationTiming(a0, a1, "domainLookup", a2, "DNS");
const r12 = a2 + msToSec(a1.requestStart);
const r46 = a2 + msToSec(a1.responseEnd);
const r52 = a2 + msToSec(a1.responseStart);
if (a1.responseEnd) {
const attributes = {};
attributes[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] = "auto.ui.browser.metrics";
startAndEndSpan(a0, r12, r46, {
op: "browser.request",
name: a1.name,
attributes
});
const attributes2 = {};
attributes2[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] = "auto.ui.browser.metrics";
startAndEndSpan(a0, r52, r46, {
op: "browser.response",
name: a1.name,
attributes: attributes2
});
}
};
_addPerformanceNavigationTiming = function _addPerformanceNavigationTiming(a0, a1, a2, a3, r13 = a2) {
const r14 = a1[a2 !== "secureConnection" ? a2 !== "fetch" ? `${a2}End` : "domainLookupStart" : "connectEnd"];
const r12 = a1[`${a2}Start`];
if (r12 && r14) {
const r38 = a3 + msToSec(r12);
const r43 = a3 + msToSec(r14);
const attributes = {};
attributes[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] = "auto.ui.browser.metrics";
HermesBuiltin.copyDataProperties(attributes, a2 === "redirect" && a1.redirectCount != null ? {
"http.redirect_count": a1.redirectCount
} : {});
startAndEndSpan(a0, r38, r43, {
op: `browser.${r13}`,
name: a1.name,
attributes
});
}
};
_addResourceSpans = function _addResourceSpans(a0, a1, a2, a3, a4, a5, ignoreResourceSpans) {
if (a1.initiatorType !== "xmlhttprequest" && a1.initiatorType !== "fetch") {
const op2 = a1.initiatorType ? `resource.${a1.initiatorType}` : "resource.other";
if (!(ignoreResourceSpans == null ? void 0 : ignoreResourceSpans.includes(op2))) {
const r5 = {};
r5[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] = "auto.resource.browser.metrics";
const r39 = parseUrl(a2);
if (r39.protocol) {
r5["url.scheme"] = r39.protocol.split(":").pop();
}
if (r39.host) {
r5["server.address"] = r39.host;
}
let env12686;
r5["url.same_origin"] = a2.includes(WINDOW.location.origin);
const r14 = [["responseStatus", "http.response.status_code"], ["transferSize", "http.response_transfer_size"], ["encodedBodySize", "http.response_content_length"], ["decodedBodySize", "http.decoded_response_content_length"], ["renderBlockingStatus", "resource.render_blocking_status"], ["deliveryType", "http.response_delivery_type"]];
const r63 = env12686 = {};
env12686[0] = a1;
env12686[1] = r5;
r14.forEach($mk67609(r63));
const attributes = {
...r5,
...resourceTimingToSpanAttributes(a1)
};
const r75 = a5 + a3;
startAndEndSpan(a0, r75, r75 + a4, {
name: a2.replace(WINDOW.location.origin, ""),
op: op2,
attributes
});
}
}
};
Object.defineProperty(exports, Symbol.toStringTag, {
value: "Module"
});
c869_5 = 0;
c869_6 = {};
export { _addMeasureSpans };
export { _addNavigationSpans };
export { _addResourceSpans };
export function _setResourceRequestAttributes(a0, a1, a2) {
let env12687;
const r1 = env12687 = {};
env12687[0] = a0;
env12687[1] = a1;
a2.forEach($mk67609(r1));
}
export function addPerformanceEntries(a0, a1) {
let c12688_2, op, start_timestamp;
const browserPerformanceAPI = getBrowserPerformanceAPI();
const r14 = browserPerformanceTimeOrigin();
if (browserPerformanceAPI?.getEntries && r14) {
const r27 = msToSec(r14);
c12688_2 = r27;
const entries = browserPerformanceAPI.getEntries();
const r32 = spanToJSON(a0);
op = r32.op;
start_timestamp = r32.start_timestamp;
entries.slice(c869_5).forEach((item) => {
L18: {
const r14 = msToSec(item.startTime);
const r31 = msToSec(Math.max(0, item.duration));
if (!(op === "navigation" && (start_timestamp && c12688_2 + r14 < start_timestamp))) {
const entryType = item.entryType;
if (entryType === "navigation") {
_addNavigationSpans(a0, item, c12688_2);
} else {
if (entryType !== "mark" && entryType !== "paint" && entryType !== "measure") {
if (entryType !== "resource") {
break L18;
}
_addResourceSpans(a0, item, item.name, r14, r31, c12688_2, a1.ignoreResourceSpans);
break L18;
}
_addMeasureSpans(a0, item, r14, r31, c12688_2, a1.ignorePerformanceApiSpans);
const r3 = item.startTime < getVisibilityWatcher().firstHiddenTime;
if (item.name === "first-paint" && r3) {
c869_6.fp = {
value: item.startTime,
unit: "millisecond"
};
}
if (item.name === "first-contentful-paint" && r3) {
c869_6.fcp = {
value: item.startTime,
unit: "millisecond"
};
}
}
}
}
});
c869_5 = Math.max(entries.length - 1, 0);
const navigator2 = WINDOW.navigator;
if (navigator2) {
const connection = navigator2.connection;
if (connection) {
if (connection.effectiveType) {
a0.setAttribute("effectiveConnectionType", connection.effectiveType);
}
if (connection.type) {
a0.setAttribute("connectionType", connection.type);
}
if (isMeasurementValue(connection.rtt)) {
c869_6["connection.rtt"] = {
value: connection.rtt,
unit: "millisecond"
};
}
}
if (isMeasurementValue(navigator2.deviceMemory)) {
a0.setAttribute.call(a0, "deviceMemory", `${navigator2.deviceMemory} GB`);
}
if (isMeasurementValue(navigator2.hardwareConcurrency)) {
a0.setAttribute("hardwareConcurrency", String(navigator2.hardwareConcurrency));
}
}
if (op === "pageload") {
const r93 = c869_6;
const navigationEntry = getNavigationEntry(false);
if (navigationEntry) {
const { responseStart, requestStart } = navigationEntry;
if (requestStart <= responseStart) {
r93["ttfb.requestTime"] = {
value: responseStart - requestStart,
unit: "millisecond"
};
}
}
if (!a1.recordClsOnPageloadSpan) {
delete c869_6["cls"];
}
if (!a1.recordLcpOnPageloadSpan) {
delete c869_6["lcp"];
}
let c12689_0;
Object.entries(c869_6).forEach((item) => {
const [r7, r24] = item;
setMeasurement(r7, r24.value, r24.unit);
});
a0.setAttribute("performance.timeOrigin", r27);
a0.setAttribute("performance.activationStart", getActivationStart());
c12689_0 = a0;
if (c869_3 && a1.recordLcpOnPageloadSpan) {
if (c869_3.element) {
a0.setAttribute("lcp.element", htmlTreeAsString(c869_3.element));
}
if (c869_3.id) {
a0.setAttribute("lcp.id", c869_3.id);
}
if (c869_3.url) {
a0.setAttribute("lcp.url", c869_3.url.trim().slice(0, 200));
}
if (c869_3.loadTime != null) {
a0.setAttribute("lcp.loadTime", c869_3.loadTime);
}
if (c869_3.renderTime != null) {
a0.setAttribute("lcp.renderTime", c869_3.renderTime);
}
a0.setAttribute("lcp.size", c869_3.size);
}
if (c869_4?.sources && a1.recordClsOnPageloadSpan) {
c869_4.sources.forEach((source, index) => c12689_0.setAttribute(`cls.source.${index + 1}`, htmlTreeAsString(source.node)));
}
}
c869_3 = void 0;
c869_4 = void 0;
c869_6 = {};
}
}
export function startTrackingInteractions() {
addPerformanceInstrumentationHandler("event", ({ entries }) => {
const activeSpan = getActiveSpan();
if (activeSpan) {
for (const item of entries) {
if (item.name === "click") {
const r22 = browserPerformanceTimeOrigin();
const startTime = msToSec(r22 + item.startTime);
const r64 = msToSec(item.duration);
const r69 = {
name: htmlTreeAsString(item.target),
op: `ui.interaction.${item.name}`,
startTime,
attributes: null
};
const attributes = {};
attributes[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] = "auto.ui.browser.metrics";
r69.attributes = attributes;
const componentName = getComponentName(item.target);
if (componentName) {
r69.attributes["ui.component_name"] = componentName;
}
startAndEndSpan(activeSpan, startTime, startTime + r64, r69);
}
}
}
});
}
export function startTrackingLongAnimationFrames() {
new PerformanceObserver((a0) => {
const activeSpan = getActiveSpan();
if (activeSpan) {
for (const item of a0.getEntries()) {
if (item.scripts[0]) {
const r61 = msToSec(browserPerformanceTimeOrigin() + item.startTime);
const r65 = spanToJSON(activeSpan);
const start_timestamp2 = r65.start_timestamp;
if (r65.op === "navigation" && start_timestamp2 && r61 < start_timestamp2) {
continue;
}
const r78 = msToSec(item.duration);
const r79 = {};
r79[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] = "auto.ui.browser.metrics";
const attributes = r79;
const r85 = item.scripts[0];
const { invoker, invokerType, sourceURL, sourceFunctionName, sourceCharPosition } = r85;
r79["browser.script.invoker"] = invoker;
r79["browser.script.invoker_type"] = invokerType;
if (sourceURL) {
attributes["code.filepath"] = sourceURL;
}
if (sourceFunctionName) {
attributes["code.function"] = sourceFunctionName;
}
if (sourceCharPosition !== -1) {
attributes["browser.script.source_char_position"] = sourceCharPosition;
}
startAndEndSpan(activeSpan, r61, r61 + r78, {
name: "Main UI thread blocked",
op: "ui.long-animation-frame",
attributes
});
}
}
}
}).observe({
type: "long-animation-frame",
buffered: true
});
}
export function startTrackingLongTasks() {
addPerformanceInstrumentationHandler("longtask", ({ entries }) => {
let r33;
const activeSpan = getActiveSpan();
if (activeSpan) {
const r43 = spanToJSON(activeSpan);
const { op: op2, start_timestamp: start_timestamp2 } = r43;
let r44 = entries[Symbol.iterator]();
const next = r44.next;
const r48 = op2 === "navigation";
while (true) {
const r50 = r44 === void 0 ? void 0 : (r33 = next.call(r44)).done ? r44 = void 0 : r33.value;
if (r44 === void 0) {
break;
}
try {
const r59 = msToSec(browserPerformanceTimeOrigin() + r50.startTime);
const r64 = msToSec(r50.duration);
if (!(r48 && start_timestamp2 && r59 < start_timestamp2)) {
const r21 = r59 + r64;
const attributes = {};
attributes[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] = "auto.ui.browser.metrics";
startAndEndSpan(activeSpan, r59, r21, {
name: "Main UI thread blocked",
op: "ui.long-task",
attributes
});
}
} catch (r79) {
if (r44 !== void 0 && typeof r44.return === "function") {
try {
r44.return();
} catch {}
}
throw r79;
}
}
}
});
}
export function startTrackingWebVitals({ recordClsStandaloneSpans, recordLcpStandaloneSpans, client }) {
let c12690_0, c12690_1, c12690_2;
c12690_0 = void 0;
c12690_1 = void 0;
c12690_2 = void 0;
const browserPerformanceAPI = getBrowserPerformanceAPI();
if (browserPerformanceAPI && browserPerformanceTimeOrigin()) {
if (browserPerformanceAPI.mark) {
WINDOW.performance.mark("sentry-tracing-init");
}
c12690_0 = recordLcpStandaloneSpans ? trackLcpAsStandaloneSpan(client) : addLcpInstrumentationHandler(({ metric }) => {
const r10 = metric.entries[metric.entries.length - 1];
if (r10) {
c869_6.lcp = {
value: metric.value,
unit: "millisecond"
};
c869_3 = r10;
}
}, true);
c12690_1 = addTtfbInstrumentationHandler(({ metric }) => {
if (metric.entries[metric.entries.length - 1]) {
c869_6.ttfb = {
value: metric.value,
unit: "millisecond"
};
}
});
c12690_2 = recordClsStandaloneSpans ? trackClsAsStandaloneSpan(client) : addClsInstrumentationHandler(({ metric }) => {
const r10 = metric.entries[metric.entries.length - 1];
if (r10) {
c869_6.cls = {
value: metric.value,
unit: ""
};
c869_4 = r10;
}
}, true);
return () => {
if (c12690_0 != null) {
c12690_0();
}
c12690_1();
if (c12690_2 != null) {
c12690_2();
}
};
}
return () => {};
}