This commit is contained in:
MarSeventh
2024-07-19 23:26:06 +08:00
commit 4e0c55d1f9
1401 changed files with 69819 additions and 0 deletions

59
node_modules/@sentry/utils/cjs/instrument/_handlers.js generated vendored Normal file
View File

@@ -0,0 +1,59 @@
Object.defineProperty(exports, '__esModule', { value: true });
const debugBuild = require('../debug-build.js');
const logger = require('../logger.js');
const stacktrace = require('../stacktrace.js');
// We keep the handlers globally
const handlers = {};
const instrumented = {};
/** Add a handler function. */
function addHandler(type, handler) {
handlers[type] = handlers[type] || [];
(handlers[type] ).push(handler);
}
/**
* Reset all instrumentation handlers.
* This can be used by tests to ensure we have a clean slate of instrumentation handlers.
*/
function resetInstrumentationHandlers() {
Object.keys(handlers).forEach(key => {
handlers[key ] = undefined;
});
}
/** Maybe run an instrumentation function, unless it was already called. */
function maybeInstrument(type, instrumentFn) {
if (!instrumented[type]) {
instrumentFn();
instrumented[type] = true;
}
}
/** Trigger handlers for a given instrumentation type. */
function triggerHandlers(type, data) {
const typeHandlers = type && handlers[type];
if (!typeHandlers) {
return;
}
for (const handler of typeHandlers) {
try {
handler(data);
} catch (e) {
debugBuild.DEBUG_BUILD &&
logger.logger.error(
`Error while triggering instrumentation handler.\nType: ${type}\nName: ${stacktrace.getFunctionName(handler)}\nError:`,
e,
);
}
}
}
exports.addHandler = addHandler;
exports.maybeInstrument = maybeInstrument;
exports.resetInstrumentationHandlers = resetInstrumentationHandlers;
exports.triggerHandlers = triggerHandlers;
//# sourceMappingURL=_handlers.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"_handlers.js","sources":["../../../src/instrument/_handlers.ts"],"sourcesContent":["import { DEBUG_BUILD } from '../debug-build';\nimport { logger } from '../logger';\nimport { getFunctionName } from '../stacktrace';\n\nexport type InstrumentHandlerType = 'console' | 'dom' | 'fetch' | 'history' | 'xhr' | 'error' | 'unhandledrejection';\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type InstrumentHandlerCallback = (data: any) => void;\n\n// We keep the handlers globally\nconst handlers: { [key in InstrumentHandlerType]?: InstrumentHandlerCallback[] } = {};\nconst instrumented: { [key in InstrumentHandlerType]?: boolean } = {};\n\n/** Add a handler function. */\nexport function addHandler(type: InstrumentHandlerType, handler: InstrumentHandlerCallback): void {\n handlers[type] = handlers[type] || [];\n (handlers[type] as InstrumentHandlerCallback[]).push(handler);\n}\n\n/**\n * Reset all instrumentation handlers.\n * This can be used by tests to ensure we have a clean slate of instrumentation handlers.\n */\nexport function resetInstrumentationHandlers(): void {\n Object.keys(handlers).forEach(key => {\n handlers[key as InstrumentHandlerType] = undefined;\n });\n}\n\n/** Maybe run an instrumentation function, unless it was already called. */\nexport function maybeInstrument(type: InstrumentHandlerType, instrumentFn: () => void): void {\n if (!instrumented[type]) {\n instrumentFn();\n instrumented[type] = true;\n }\n}\n\n/** Trigger handlers for a given instrumentation type. */\nexport function triggerHandlers(type: InstrumentHandlerType, data: unknown): void {\n const typeHandlers = type && handlers[type];\n if (!typeHandlers) {\n return;\n }\n\n for (const handler of typeHandlers) {\n try {\n handler(data);\n } catch (e) {\n DEBUG_BUILD &&\n logger.error(\n `Error while triggering instrumentation handler.\\nType: ${type}\\nName: ${getFunctionName(handler)}\\nError:`,\n e,\n );\n }\n }\n}\n"],"names":["DEBUG_BUILD","logger","getFunctionName"],"mappings":";;;;;;AAQA;AACA,MAAM,QAAQ,GAAqE,EAAE,CAAA;AACrF,MAAM,YAAY,GAAiD,EAAE,CAAA;AACrE;AACA;AACO,SAAS,UAAU,CAAC,IAAI,EAAyB,OAAO,EAAmC;AAClG,EAAE,QAAQ,CAAC,IAAI,CAAE,GAAE,QAAQ,CAAC,IAAI,CAAA,IAAK,EAAE,CAAA;AACvC,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAA,GAAkC,IAAI,CAAC,OAAO,CAAC,CAAA;AAC/D,CAAA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,4BAA4B,GAAS;AACrD,EAAE,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,GAAA,IAAO;AACvC,IAAI,QAAQ,CAAC,GAAI,EAAA,GAA4B,SAAS,CAAA;AACtD,GAAG,CAAC,CAAA;AACJ,CAAA;AACA;AACA;AACO,SAAS,eAAe,CAAC,IAAI,EAAyB,YAAY,EAAoB;AAC7F,EAAE,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE;AAC3B,IAAI,YAAY,EAAE,CAAA;AAClB,IAAI,YAAY,CAAC,IAAI,CAAA,GAAI,IAAI,CAAA;AAC7B,GAAE;AACF,CAAA;AACA;AACA;AACO,SAAS,eAAe,CAAC,IAAI,EAAyB,IAAI,EAAiB;AAClF,EAAE,MAAM,eAAe,IAAA,IAAQ,QAAQ,CAAC,IAAI,CAAC,CAAA;AAC7C,EAAE,IAAI,CAAC,YAAY,EAAE;AACrB,IAAI,OAAM;AACV,GAAE;AACF;AACA,EAAE,KAAK,MAAM,OAAQ,IAAG,YAAY,EAAE;AACtC,IAAI,IAAI;AACR,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;AACnB,KAAM,CAAA,OAAO,CAAC,EAAE;AAChB,MAAMA,sBAAY;AAClB,QAAQC,aAAM,CAAC,KAAK;AACpB,UAAU,CAAC,uDAAuD,EAAE,IAAI,CAAC,QAAQ,EAAEC,0BAAe,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC;AACrH,UAAU,CAAC;AACX,SAAS,CAAA;AACT,KAAI;AACJ,GAAE;AACF;;;;;;;"}

45
node_modules/@sentry/utils/cjs/instrument/console.js generated vendored Normal file
View File

@@ -0,0 +1,45 @@
Object.defineProperty(exports, '__esModule', { value: true });
const logger = require('../logger.js');
const object = require('../object.js');
const worldwide = require('../worldwide.js');
const _handlers = require('./_handlers.js');
/**
* Add an instrumentation handler for when a console.xxx method is called.
*
* Use at your own risk, this might break without changelog notice, only used internally.
* @hidden
*/
function addConsoleInstrumentationHandler(handler) {
const type = 'console';
_handlers.addHandler(type, handler);
_handlers.maybeInstrument(type, instrumentConsole);
}
function instrumentConsole() {
if (!('console' in worldwide.GLOBAL_OBJ)) {
return;
}
logger.CONSOLE_LEVELS.forEach(function (level) {
if (!(level in worldwide.GLOBAL_OBJ.console)) {
return;
}
object.fill(worldwide.GLOBAL_OBJ.console, level, function (originalConsoleMethod) {
logger.originalConsoleMethods[level] = originalConsoleMethod;
return function (...args) {
const handlerData = { args, level };
_handlers.triggerHandlers('console', handlerData);
const log = logger.originalConsoleMethods[level];
log && log.apply(worldwide.GLOBAL_OBJ.console, args);
};
});
});
}
exports.addConsoleInstrumentationHandler = addConsoleInstrumentationHandler;
//# sourceMappingURL=console.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"console.js","sources":["../../../src/instrument/console.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/ban-types */\nimport type { ConsoleLevel, HandlerDataConsole } from '@sentry/types';\n\nimport { CONSOLE_LEVELS, originalConsoleMethods } from '../logger';\nimport { fill } from '../object';\nimport { GLOBAL_OBJ } from '../worldwide';\nimport { addHandler, maybeInstrument, triggerHandlers } from './_handlers';\n\n/**\n * Add an instrumentation handler for when a console.xxx method is called.\n *\n * Use at your own risk, this might break without changelog notice, only used internally.\n * @hidden\n */\nexport function addConsoleInstrumentationHandler(handler: (data: HandlerDataConsole) => void): void {\n const type = 'console';\n addHandler(type, handler);\n maybeInstrument(type, instrumentConsole);\n}\n\nfunction instrumentConsole(): void {\n if (!('console' in GLOBAL_OBJ)) {\n return;\n }\n\n CONSOLE_LEVELS.forEach(function (level: ConsoleLevel): void {\n if (!(level in GLOBAL_OBJ.console)) {\n return;\n }\n\n fill(GLOBAL_OBJ.console, level, function (originalConsoleMethod: () => any): Function {\n originalConsoleMethods[level] = originalConsoleMethod;\n\n return function (...args: any[]): void {\n const handlerData: HandlerDataConsole = { args, level };\n triggerHandlers('console', handlerData);\n\n const log = originalConsoleMethods[level];\n log && log.apply(GLOBAL_OBJ.console, args);\n };\n });\n });\n}\n"],"names":["addHandler","maybeInstrument","GLOBAL_OBJ","CONSOLE_LEVELS","fill","originalConsoleMethods","triggerHandlers"],"mappings":";;;;;;;AASA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,gCAAgC,CAAC,OAAO,EAA4C;AACpG,EAAE,MAAM,IAAK,GAAE,SAAS,CAAA;AACxB,EAAEA,oBAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;AAC3B,EAAEC,yBAAe,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAA;AAC1C,CAAA;AACA;AACA,SAAS,iBAAiB,GAAS;AACnC,EAAE,IAAI,EAAE,aAAaC,oBAAU,CAAC,EAAE;AAClC,IAAI,OAAM;AACV,GAAE;AACF;AACA,EAAEC,qBAAc,CAAC,OAAO,CAAC,UAAU,KAAK,EAAsB;AAC9D,IAAI,IAAI,EAAE,KAAA,IAASD,oBAAU,CAAC,OAAO,CAAC,EAAE;AACxC,MAAM,OAAM;AACZ,KAAI;AACJ;AACA,IAAIE,WAAI,CAACF,oBAAU,CAAC,OAAO,EAAE,KAAK,EAAE,UAAU,qBAAqB,EAAuB;AAC1F,MAAMG,6BAAsB,CAAC,KAAK,CAAA,GAAI,qBAAqB,CAAA;AAC3D;AACA,MAAM,OAAO,UAAU,GAAG,IAAI,EAAe;AAC7C,QAAQ,MAAM,WAAW,GAAuB,EAAE,IAAI,EAAE,OAAO,CAAA;AAC/D,QAAQC,yBAAe,CAAC,SAAS,EAAE,WAAW,CAAC,CAAA;AAC/C;AACA,QAAQ,MAAM,GAAI,GAAED,6BAAsB,CAAC,KAAK,CAAC,CAAA;AACjD,QAAQ,GAAA,IAAO,GAAG,CAAC,KAAK,CAACH,oBAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;AAClD,OAAO,CAAA;AACP,KAAK,CAAC,CAAA;AACN,GAAG,CAAC,CAAA;AACJ;;;;"}

239
node_modules/@sentry/utils/cjs/instrument/dom.js generated vendored Normal file
View File

@@ -0,0 +1,239 @@
Object.defineProperty(exports, '__esModule', { value: true });
const misc = require('../misc.js');
const object = require('../object.js');
const worldwide = require('../worldwide.js');
const _handlers = require('./_handlers.js');
const WINDOW = worldwide.GLOBAL_OBJ ;
const DEBOUNCE_DURATION = 1000;
let debounceTimerID;
let lastCapturedEventType;
let lastCapturedEventTargetId;
/**
* Add an instrumentation handler for when a click or a keypress happens.
*
* Use at your own risk, this might break without changelog notice, only used internally.
* @hidden
*/
function addClickKeypressInstrumentationHandler(handler) {
const type = 'dom';
_handlers.addHandler(type, handler);
_handlers.maybeInstrument(type, instrumentDOM);
}
/** Exported for tests only. */
function instrumentDOM() {
if (!WINDOW.document) {
return;
}
// Make it so that any click or keypress that is unhandled / bubbled up all the way to the document triggers our dom
// handlers. (Normally we have only one, which captures a breadcrumb for each click or keypress.) Do this before
// we instrument `addEventListener` so that we don't end up attaching this handler twice.
const triggerDOMHandler = _handlers.triggerHandlers.bind(null, 'dom');
const globalDOMEventHandler = makeDOMEventHandler(triggerDOMHandler, true);
WINDOW.document.addEventListener('click', globalDOMEventHandler, false);
WINDOW.document.addEventListener('keypress', globalDOMEventHandler, false);
// After hooking into click and keypress events bubbled up to `document`, we also hook into user-handled
// clicks & keypresses, by adding an event listener of our own to any element to which they add a listener. That
// way, whenever one of their handlers is triggered, ours will be, too. (This is needed because their handler
// could potentially prevent the event from bubbling up to our global listeners. This way, our handler are still
// guaranteed to fire at least once.)
['EventTarget', 'Node'].forEach((target) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const proto = (WINDOW )[target] && (WINDOW )[target].prototype;
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, no-prototype-builtins
if (!proto || !proto.hasOwnProperty || !proto.hasOwnProperty('addEventListener')) {
return;
}
object.fill(proto, 'addEventListener', function (originalAddEventListener) {
return function (
type,
listener,
options,
) {
if (type === 'click' || type == 'keypress') {
try {
const el = this ;
const handlers = (el.__sentry_instrumentation_handlers__ = el.__sentry_instrumentation_handlers__ || {});
const handlerForType = (handlers[type] = handlers[type] || { refCount: 0 });
if (!handlerForType.handler) {
const handler = makeDOMEventHandler(triggerDOMHandler);
handlerForType.handler = handler;
originalAddEventListener.call(this, type, handler, options);
}
handlerForType.refCount++;
} catch (e) {
// Accessing dom properties is always fragile.
// Also allows us to skip `addEventListenrs` calls with no proper `this` context.
}
}
return originalAddEventListener.call(this, type, listener, options);
};
});
object.fill(
proto,
'removeEventListener',
function (originalRemoveEventListener) {
return function (
type,
listener,
options,
) {
if (type === 'click' || type == 'keypress') {
try {
const el = this ;
const handlers = el.__sentry_instrumentation_handlers__ || {};
const handlerForType = handlers[type];
if (handlerForType) {
handlerForType.refCount--;
// If there are no longer any custom handlers of the current type on this element, we can remove ours, too.
if (handlerForType.refCount <= 0) {
originalRemoveEventListener.call(this, type, handlerForType.handler, options);
handlerForType.handler = undefined;
delete handlers[type]; // eslint-disable-line @typescript-eslint/no-dynamic-delete
}
// If there are no longer any custom handlers of any type on this element, cleanup everything.
if (Object.keys(handlers).length === 0) {
delete el.__sentry_instrumentation_handlers__;
}
}
} catch (e) {
// Accessing dom properties is always fragile.
// Also allows us to skip `addEventListenrs` calls with no proper `this` context.
}
}
return originalRemoveEventListener.call(this, type, listener, options);
};
},
);
});
}
/**
* Check whether the event is similar to the last captured one. For example, two click events on the same button.
*/
function isSimilarToLastCapturedEvent(event) {
// If both events have different type, then user definitely performed two separate actions. e.g. click + keypress.
if (event.type !== lastCapturedEventType) {
return false;
}
try {
// If both events have the same type, it's still possible that actions were performed on different targets.
// e.g. 2 clicks on different buttons.
if (!event.target || (event.target )._sentryId !== lastCapturedEventTargetId) {
return false;
}
} catch (e) {
// just accessing `target` property can throw an exception in some rare circumstances
// see: https://github.com/getsentry/sentry-javascript/issues/838
}
// If both events have the same type _and_ same `target` (an element which triggered an event, _not necessarily_
// to which an event listener was attached), we treat them as the same action, as we want to capture
// only one breadcrumb. e.g. multiple clicks on the same button, or typing inside a user input box.
return true;
}
/**
* Decide whether an event should be captured.
* @param event event to be captured
*/
function shouldSkipDOMEvent(eventType, target) {
// We are only interested in filtering `keypress` events for now.
if (eventType !== 'keypress') {
return false;
}
if (!target || !target.tagName) {
return true;
}
// Only consider keypress events on actual input elements. This will disregard keypresses targeting body
// e.g.tabbing through elements, hotkeys, etc.
if (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.isContentEditable) {
return false;
}
return true;
}
/**
* Wraps addEventListener to capture UI breadcrumbs
*/
function makeDOMEventHandler(
handler,
globalListener = false,
) {
return (event) => {
// It's possible this handler might trigger multiple times for the same
// event (e.g. event propagation through node ancestors).
// Ignore if we've already captured that event.
if (!event || event['_sentryCaptured']) {
return;
}
const target = getEventTarget(event);
// We always want to skip _some_ events.
if (shouldSkipDOMEvent(event.type, target)) {
return;
}
// Mark event as "seen"
object.addNonEnumerableProperty(event, '_sentryCaptured', true);
if (target && !target._sentryId) {
// Add UUID to event target so we can identify if
object.addNonEnumerableProperty(target, '_sentryId', misc.uuid4());
}
const name = event.type === 'keypress' ? 'input' : event.type;
// If there is no last captured event, it means that we can safely capture the new event and store it for future comparisons.
// If there is a last captured event, see if the new event is different enough to treat it as a unique one.
// If that's the case, emit the previous event and store locally the newly-captured DOM event.
if (!isSimilarToLastCapturedEvent(event)) {
const handlerData = { event, name, global: globalListener };
handler(handlerData);
lastCapturedEventType = event.type;
lastCapturedEventTargetId = target ? target._sentryId : undefined;
}
// Start a new debounce timer that will prevent us from capturing multiple events that should be grouped together.
clearTimeout(debounceTimerID);
debounceTimerID = WINDOW.setTimeout(() => {
lastCapturedEventTargetId = undefined;
lastCapturedEventType = undefined;
}, DEBOUNCE_DURATION);
};
}
function getEventTarget(event) {
try {
return event.target ;
} catch (e) {
// just accessing `target` property can throw an exception in some rare circumstances
// see: https://github.com/getsentry/sentry-javascript/issues/838
return null;
}
}
exports.addClickKeypressInstrumentationHandler = addClickKeypressInstrumentationHandler;
exports.instrumentDOM = instrumentDOM;
//# sourceMappingURL=dom.js.map

1
node_modules/@sentry/utils/cjs/instrument/dom.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

125
node_modules/@sentry/utils/cjs/instrument/fetch.js generated vendored Normal file
View File

@@ -0,0 +1,125 @@
Object.defineProperty(exports, '__esModule', { value: true });
const object = require('../object.js');
const supports = require('../supports.js');
const worldwide = require('../worldwide.js');
const _handlers = require('./_handlers.js');
/**
* Add an instrumentation handler for when a fetch request happens.
* The handler function is called once when the request starts and once when it ends,
* which can be identified by checking if it has an `endTimestamp`.
*
* Use at your own risk, this might break without changelog notice, only used internally.
* @hidden
*/
function addFetchInstrumentationHandler(handler) {
const type = 'fetch';
_handlers.addHandler(type, handler);
_handlers.maybeInstrument(type, instrumentFetch);
}
function instrumentFetch() {
if (!supports.supportsNativeFetch()) {
return;
}
object.fill(worldwide.GLOBAL_OBJ, 'fetch', function (originalFetch) {
return function (...args) {
const { method, url } = parseFetchArgs(args);
const handlerData = {
args,
fetchData: {
method,
url,
},
startTimestamp: Date.now(),
};
_handlers.triggerHandlers('fetch', {
...handlerData,
});
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
return originalFetch.apply(worldwide.GLOBAL_OBJ, args).then(
(response) => {
const finishedHandlerData = {
...handlerData,
endTimestamp: Date.now(),
response,
};
_handlers.triggerHandlers('fetch', finishedHandlerData);
return response;
},
(error) => {
const erroredHandlerData = {
...handlerData,
endTimestamp: Date.now(),
error,
};
_handlers.triggerHandlers('fetch', erroredHandlerData);
// NOTE: If you are a Sentry user, and you are seeing this stack frame,
// it means the sentry.javascript SDK caught an error invoking your application code.
// This is expected behavior and NOT indicative of a bug with sentry.javascript.
throw error;
},
);
};
});
}
function hasProp(obj, prop) {
return !!obj && typeof obj === 'object' && !!(obj )[prop];
}
function getUrlFromResource(resource) {
if (typeof resource === 'string') {
return resource;
}
if (!resource) {
return '';
}
if (hasProp(resource, 'url')) {
return resource.url;
}
if (resource.toString) {
return resource.toString();
}
return '';
}
/**
* Parses the fetch arguments to find the used Http method and the url of the request.
* Exported for tests only.
*/
function parseFetchArgs(fetchArgs) {
if (fetchArgs.length === 0) {
return { method: 'GET', url: '' };
}
if (fetchArgs.length === 2) {
const [url, options] = fetchArgs ;
return {
url: getUrlFromResource(url),
method: hasProp(options, 'method') ? String(options.method).toUpperCase() : 'GET',
};
}
const arg = fetchArgs[0];
return {
url: getUrlFromResource(arg ),
method: hasProp(arg, 'method') ? String(arg.method).toUpperCase() : 'GET',
};
}
exports.addFetchInstrumentationHandler = addFetchInstrumentationHandler;
exports.parseFetchArgs = parseFetchArgs;
//# sourceMappingURL=fetch.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,51 @@
Object.defineProperty(exports, '__esModule', { value: true });
const worldwide = require('../worldwide.js');
const _handlers = require('./_handlers.js');
let _oldOnErrorHandler = null;
/**
* Add an instrumentation handler for when an error is captured by the global error handler.
*
* Use at your own risk, this might break without changelog notice, only used internally.
* @hidden
*/
function addGlobalErrorInstrumentationHandler(handler) {
const type = 'error';
_handlers.addHandler(type, handler);
_handlers.maybeInstrument(type, instrumentError);
}
function instrumentError() {
_oldOnErrorHandler = worldwide.GLOBAL_OBJ.onerror;
worldwide.GLOBAL_OBJ.onerror = function (
msg,
url,
line,
column,
error,
) {
const handlerData = {
column,
error,
line,
msg,
url,
};
_handlers.triggerHandlers('error', handlerData);
if (_oldOnErrorHandler && !_oldOnErrorHandler.__SENTRY_LOADER__) {
// eslint-disable-next-line prefer-rest-params
return _oldOnErrorHandler.apply(this, arguments);
}
return false;
};
worldwide.GLOBAL_OBJ.onerror.__SENTRY_INSTRUMENTED__ = true;
}
exports.addGlobalErrorInstrumentationHandler = addGlobalErrorInstrumentationHandler;
//# sourceMappingURL=globalError.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"globalError.js","sources":["../../../src/instrument/globalError.ts"],"sourcesContent":["import type { HandlerDataError } from '@sentry/types';\n\nimport { GLOBAL_OBJ } from '../worldwide';\nimport { addHandler, maybeInstrument, triggerHandlers } from './_handlers';\n\nlet _oldOnErrorHandler: (typeof GLOBAL_OBJ)['onerror'] | null = null;\n\n/**\n * Add an instrumentation handler for when an error is captured by the global error handler.\n *\n * Use at your own risk, this might break without changelog notice, only used internally.\n * @hidden\n */\nexport function addGlobalErrorInstrumentationHandler(handler: (data: HandlerDataError) => void): void {\n const type = 'error';\n addHandler(type, handler);\n maybeInstrument(type, instrumentError);\n}\n\nfunction instrumentError(): void {\n _oldOnErrorHandler = GLOBAL_OBJ.onerror;\n\n GLOBAL_OBJ.onerror = function (\n msg: string | object,\n url?: string,\n line?: number,\n column?: number,\n error?: Error,\n ): boolean {\n const handlerData: HandlerDataError = {\n column,\n error,\n line,\n msg,\n url,\n };\n triggerHandlers('error', handlerData);\n\n if (_oldOnErrorHandler && !_oldOnErrorHandler.__SENTRY_LOADER__) {\n // eslint-disable-next-line prefer-rest-params\n return _oldOnErrorHandler.apply(this, arguments);\n }\n\n return false;\n };\n\n GLOBAL_OBJ.onerror.__SENTRY_INSTRUMENTED__ = true;\n}\n"],"names":["addHandler","maybeInstrument","GLOBAL_OBJ","triggerHandlers"],"mappings":";;;;;AAKA,IAAI,kBAAkB,GAA0C,IAAI,CAAA;AACpE;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,oCAAoC,CAAC,OAAO,EAA0C;AACtG,EAAE,MAAM,IAAK,GAAE,OAAO,CAAA;AACtB,EAAEA,oBAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;AAC3B,EAAEC,yBAAe,CAAC,IAAI,EAAE,eAAe,CAAC,CAAA;AACxC,CAAA;AACA;AACA,SAAS,eAAe,GAAS;AACjC,EAAE,kBAAmB,GAAEC,oBAAU,CAAC,OAAO,CAAA;AACzC;AACA,EAAEA,oBAAU,CAAC,OAAQ,GAAE;AACvB,IAAI,GAAG;AACP,IAAI,GAAG;AACP,IAAI,IAAI;AACR,IAAI,MAAM;AACV,IAAI,KAAK;AACT,IAAa;AACb,IAAI,MAAM,WAAW,GAAqB;AAC1C,MAAM,MAAM;AACZ,MAAM,KAAK;AACX,MAAM,IAAI;AACV,MAAM,GAAG;AACT,MAAM,GAAG;AACT,KAAK,CAAA;AACL,IAAIC,yBAAe,CAAC,OAAO,EAAE,WAAW,CAAC,CAAA;AACzC;AACA,IAAI,IAAI,kBAAmB,IAAG,CAAC,kBAAkB,CAAC,iBAAiB,EAAE;AACrE;AACA,MAAM,OAAO,kBAAkB,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAA;AACtD,KAAI;AACJ;AACA,IAAI,OAAO,KAAK,CAAA;AAChB,GAAG,CAAA;AACH;AACA,EAAED,oBAAU,CAAC,OAAO,CAAC,uBAAA,GAA0B,IAAI,CAAA;AACnD;;;;"}

View File

@@ -0,0 +1,41 @@
Object.defineProperty(exports, '__esModule', { value: true });
const worldwide = require('../worldwide.js');
const _handlers = require('./_handlers.js');
let _oldOnUnhandledRejectionHandler = null;
/**
* Add an instrumentation handler for when an unhandled promise rejection is captured.
*
* Use at your own risk, this might break without changelog notice, only used internally.
* @hidden
*/
function addGlobalUnhandledRejectionInstrumentationHandler(
handler,
) {
const type = 'unhandledrejection';
_handlers.addHandler(type, handler);
_handlers.maybeInstrument(type, instrumentUnhandledRejection);
}
function instrumentUnhandledRejection() {
_oldOnUnhandledRejectionHandler = worldwide.GLOBAL_OBJ.onunhandledrejection;
worldwide.GLOBAL_OBJ.onunhandledrejection = function (e) {
const handlerData = e;
_handlers.triggerHandlers('unhandledrejection', handlerData);
if (_oldOnUnhandledRejectionHandler && !_oldOnUnhandledRejectionHandler.__SENTRY_LOADER__) {
// eslint-disable-next-line prefer-rest-params
return _oldOnUnhandledRejectionHandler.apply(this, arguments);
}
return true;
};
worldwide.GLOBAL_OBJ.onunhandledrejection.__SENTRY_INSTRUMENTED__ = true;
}
exports.addGlobalUnhandledRejectionInstrumentationHandler = addGlobalUnhandledRejectionInstrumentationHandler;
//# sourceMappingURL=globalUnhandledRejection.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"globalUnhandledRejection.js","sources":["../../../src/instrument/globalUnhandledRejection.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport type { HandlerDataUnhandledRejection } from '@sentry/types';\n\nimport { GLOBAL_OBJ } from '../worldwide';\nimport { addHandler, maybeInstrument, triggerHandlers } from './_handlers';\n\nlet _oldOnUnhandledRejectionHandler: (typeof GLOBAL_OBJ)['onunhandledrejection'] | null = null;\n\n/**\n * Add an instrumentation handler for when an unhandled promise rejection is captured.\n *\n * Use at your own risk, this might break without changelog notice, only used internally.\n * @hidden\n */\nexport function addGlobalUnhandledRejectionInstrumentationHandler(\n handler: (data: HandlerDataUnhandledRejection) => void,\n): void {\n const type = 'unhandledrejection';\n addHandler(type, handler);\n maybeInstrument(type, instrumentUnhandledRejection);\n}\n\nfunction instrumentUnhandledRejection(): void {\n _oldOnUnhandledRejectionHandler = GLOBAL_OBJ.onunhandledrejection;\n\n GLOBAL_OBJ.onunhandledrejection = function (e: any): boolean {\n const handlerData: HandlerDataUnhandledRejection = e;\n triggerHandlers('unhandledrejection', handlerData);\n\n if (_oldOnUnhandledRejectionHandler && !_oldOnUnhandledRejectionHandler.__SENTRY_LOADER__) {\n // eslint-disable-next-line prefer-rest-params\n return _oldOnUnhandledRejectionHandler.apply(this, arguments);\n }\n\n return true;\n };\n\n GLOBAL_OBJ.onunhandledrejection.__SENTRY_INSTRUMENTED__ = true;\n}\n"],"names":["addHandler","maybeInstrument","GLOBAL_OBJ","triggerHandlers"],"mappings":";;;;;AAOA,IAAI,+BAA+B,GAAuD,IAAI,CAAA;AAC9F;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,iDAAiD;AACjE,EAAE,OAAO;AACT,EAAQ;AACR,EAAE,MAAM,IAAK,GAAE,oBAAoB,CAAA;AACnC,EAAEA,oBAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;AAC3B,EAAEC,yBAAe,CAAC,IAAI,EAAE,4BAA4B,CAAC,CAAA;AACrD,CAAA;AACA;AACA,SAAS,4BAA4B,GAAS;AAC9C,EAAE,+BAAgC,GAAEC,oBAAU,CAAC,oBAAoB,CAAA;AACnE;AACA,EAAEA,oBAAU,CAAC,oBAAqB,GAAE,UAAU,CAAC,EAAgB;AAC/D,IAAI,MAAM,WAAW,GAAkC,CAAC,CAAA;AACxD,IAAIC,yBAAe,CAAC,oBAAoB,EAAE,WAAW,CAAC,CAAA;AACtD;AACA,IAAI,IAAI,+BAAgC,IAAG,CAAC,+BAA+B,CAAC,iBAAiB,EAAE;AAC/F;AACA,MAAM,OAAO,+BAA+B,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAA;AACnE,KAAI;AACJ;AACA,IAAI,OAAO,IAAI,CAAA;AACf,GAAG,CAAA;AACH;AACA,EAAED,oBAAU,CAAC,oBAAoB,CAAC,uBAAA,GAA0B,IAAI,CAAA;AAChE;;;;"}

74
node_modules/@sentry/utils/cjs/instrument/history.js generated vendored Normal file
View File

@@ -0,0 +1,74 @@
Object.defineProperty(exports, '__esModule', { value: true });
const object = require('../object.js');
require('../debug-build.js');
require('../logger.js');
const worldwide = require('../worldwide.js');
const supportsHistory = require('../vendor/supportsHistory.js');
const _handlers = require('./_handlers.js');
const WINDOW = worldwide.GLOBAL_OBJ ;
let lastHref;
/**
* Add an instrumentation handler for when a fetch request happens.
* The handler function is called once when the request starts and once when it ends,
* which can be identified by checking if it has an `endTimestamp`.
*
* Use at your own risk, this might break without changelog notice, only used internally.
* @hidden
*/
function addHistoryInstrumentationHandler(handler) {
const type = 'history';
_handlers.addHandler(type, handler);
_handlers.maybeInstrument(type, instrumentHistory);
}
function instrumentHistory() {
if (!supportsHistory.supportsHistory()) {
return;
}
const oldOnPopState = WINDOW.onpopstate;
WINDOW.onpopstate = function ( ...args) {
const to = WINDOW.location.href;
// keep track of the current URL state, as we always receive only the updated state
const from = lastHref;
lastHref = to;
const handlerData = { from, to };
_handlers.triggerHandlers('history', handlerData);
if (oldOnPopState) {
// Apparently this can throw in Firefox when incorrectly implemented plugin is installed.
// https://github.com/getsentry/sentry-javascript/issues/3344
// https://github.com/bugsnag/bugsnag-js/issues/469
try {
return oldOnPopState.apply(this, args);
} catch (_oO) {
// no-empty
}
}
};
function historyReplacementFunction(originalHistoryFunction) {
return function ( ...args) {
const url = args.length > 2 ? args[2] : undefined;
if (url) {
// coerce to string (this is what pushState does)
const from = lastHref;
const to = String(url);
// keep track of the current URL state, as we always receive only the updated state
lastHref = to;
const handlerData = { from, to };
_handlers.triggerHandlers('history', handlerData);
}
return originalHistoryFunction.apply(this, args);
};
}
object.fill(WINDOW.history, 'pushState', historyReplacementFunction);
object.fill(WINDOW.history, 'replaceState', historyReplacementFunction);
}
exports.addHistoryInstrumentationHandler = addHistoryInstrumentationHandler;
//# sourceMappingURL=history.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"history.js","sources":["../../../src/instrument/history.ts"],"sourcesContent":["// TODO(v8): Move everything in this file into the browser package. Nothing here is generic and we run risk of leaking browser types into non-browser packages.\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/ban-types */\nimport type { HandlerDataHistory } from '@sentry/types';\n\nimport { fill } from '../object';\nimport { supportsHistory } from '../supports';\nimport { GLOBAL_OBJ } from '../worldwide';\nimport { addHandler, maybeInstrument, triggerHandlers } from './_handlers';\n\nconst WINDOW = GLOBAL_OBJ as unknown as Window;\n\nlet lastHref: string | undefined;\n\n/**\n * Add an instrumentation handler for when a fetch request happens.\n * The handler function is called once when the request starts and once when it ends,\n * which can be identified by checking if it has an `endTimestamp`.\n *\n * Use at your own risk, this might break without changelog notice, only used internally.\n * @hidden\n */\nexport function addHistoryInstrumentationHandler(handler: (data: HandlerDataHistory) => void): void {\n const type = 'history';\n addHandler(type, handler);\n maybeInstrument(type, instrumentHistory);\n}\n\nfunction instrumentHistory(): void {\n if (!supportsHistory()) {\n return;\n }\n\n const oldOnPopState = WINDOW.onpopstate;\n WINDOW.onpopstate = function (this: WindowEventHandlers, ...args: any[]): any {\n const to = WINDOW.location.href;\n // keep track of the current URL state, as we always receive only the updated state\n const from = lastHref;\n lastHref = to;\n const handlerData: HandlerDataHistory = { from, to };\n triggerHandlers('history', handlerData);\n if (oldOnPopState) {\n // Apparently this can throw in Firefox when incorrectly implemented plugin is installed.\n // https://github.com/getsentry/sentry-javascript/issues/3344\n // https://github.com/bugsnag/bugsnag-js/issues/469\n try {\n return oldOnPopState.apply(this, args);\n } catch (_oO) {\n // no-empty\n }\n }\n };\n\n function historyReplacementFunction(originalHistoryFunction: () => void): () => void {\n return function (this: History, ...args: any[]): void {\n const url = args.length > 2 ? args[2] : undefined;\n if (url) {\n // coerce to string (this is what pushState does)\n const from = lastHref;\n const to = String(url);\n // keep track of the current URL state, as we always receive only the updated state\n lastHref = to;\n const handlerData: HandlerDataHistory = { from, to };\n triggerHandlers('history', handlerData);\n }\n return originalHistoryFunction.apply(this, args);\n };\n }\n\n fill(WINDOW.history, 'pushState', historyReplacementFunction);\n fill(WINDOW.history, 'replaceState', historyReplacementFunction);\n}\n"],"names":["GLOBAL_OBJ","addHandler","maybeInstrument","supportsHistory","triggerHandlers","fill"],"mappings":";;;;;;;;;AAWA,MAAM,MAAA,GAASA,oBAAW,EAAA;AAC1B;AACA,IAAI,QAAQ,CAAA;AACZ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,gCAAgC,CAAC,OAAO,EAA4C;AACpG,EAAE,MAAM,IAAK,GAAE,SAAS,CAAA;AACxB,EAAEC,oBAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;AAC3B,EAAEC,yBAAe,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAA;AAC1C,CAAA;AACA;AACA,SAAS,iBAAiB,GAAS;AACnC,EAAE,IAAI,CAACC,+BAAe,EAAE,EAAE;AAC1B,IAAI,OAAM;AACV,GAAE;AACF;AACA,EAAE,MAAM,aAAA,GAAgB,MAAM,CAAC,UAAU,CAAA;AACzC,EAAE,MAAM,CAAC,UAAA,GAAa,WAAqC,GAAG,IAAI,EAAc;AAChF,IAAI,MAAM,EAAG,GAAE,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAA;AACnC;AACA,IAAI,MAAM,IAAK,GAAE,QAAQ,CAAA;AACzB,IAAI,QAAA,GAAW,EAAE,CAAA;AACjB,IAAI,MAAM,WAAW,GAAuB,EAAE,IAAI,EAAE,IAAI,CAAA;AACxD,IAAIC,yBAAe,CAAC,SAAS,EAAE,WAAW,CAAC,CAAA;AAC3C,IAAI,IAAI,aAAa,EAAE;AACvB;AACA;AACA;AACA,MAAM,IAAI;AACV,QAAQ,OAAO,aAAa,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;AAC9C,OAAQ,CAAA,OAAO,GAAG,EAAE;AACpB;AACA,OAAM;AACN,KAAI;AACJ,GAAG,CAAA;AACH;AACA,EAAE,SAAS,0BAA0B,CAAC,uBAAuB,EAA0B;AACvF,IAAI,OAAO,WAAyB,GAAG,IAAI,EAAe;AAC1D,MAAM,MAAM,GAAA,GAAM,IAAI,CAAC,MAAO,GAAE,CAAE,GAAE,IAAI,CAAC,CAAC,CAAA,GAAI,SAAS,CAAA;AACvD,MAAM,IAAI,GAAG,EAAE;AACf;AACA,QAAQ,MAAM,IAAK,GAAE,QAAQ,CAAA;AAC7B,QAAQ,MAAM,EAAG,GAAE,MAAM,CAAC,GAAG,CAAC,CAAA;AAC9B;AACA,QAAQ,QAAA,GAAW,EAAE,CAAA;AACrB,QAAQ,MAAM,WAAW,GAAuB,EAAE,IAAI,EAAE,IAAI,CAAA;AAC5D,QAAQA,yBAAe,CAAC,SAAS,EAAE,WAAW,CAAC,CAAA;AAC/C,OAAM;AACN,MAAM,OAAO,uBAAuB,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;AACtD,KAAK,CAAA;AACL,GAAE;AACF;AACA,EAAEC,WAAI,CAAC,MAAM,CAAC,OAAO,EAAE,WAAW,EAAE,0BAA0B,CAAC,CAAA;AAC/D,EAAEA,WAAI,CAAC,MAAM,CAAC,OAAO,EAAE,cAAc,EAAE,0BAA0B,CAAC,CAAA;AAClE;;;;"}

51
node_modules/@sentry/utils/cjs/instrument/index.js generated vendored Normal file
View File

@@ -0,0 +1,51 @@
Object.defineProperty(exports, '__esModule', { value: true });
const debugBuild = require('../debug-build.js');
const logger = require('../logger.js');
const console = require('./console.js');
const dom = require('./dom.js');
const fetch = require('./fetch.js');
const globalError = require('./globalError.js');
const globalUnhandledRejection = require('./globalUnhandledRejection.js');
const history = require('./history.js');
const xhr = require('./xhr.js');
// TODO(v8): Consider moving this file (or at least parts of it) into the browser package. The registered handlers are mostly non-generic and we risk leaking runtime specific code into generic packages.
/**
* Add handler that will be called when given type of instrumentation triggers.
* Use at your own risk, this might break without changelog notice, only used internally.
* @hidden
* @deprecated Use the proper function per instrumentation type instead!
*/
function addInstrumentationHandler(type, callback) {
switch (type) {
case 'console':
return console.addConsoleInstrumentationHandler(callback);
case 'dom':
return dom.addClickKeypressInstrumentationHandler(callback);
case 'xhr':
return xhr.addXhrInstrumentationHandler(callback);
case 'fetch':
return fetch.addFetchInstrumentationHandler(callback);
case 'history':
return history.addHistoryInstrumentationHandler(callback);
case 'error':
return globalError.addGlobalErrorInstrumentationHandler(callback);
case 'unhandledrejection':
return globalUnhandledRejection.addGlobalUnhandledRejectionInstrumentationHandler(callback);
default:
debugBuild.DEBUG_BUILD && logger.logger.warn('unknown instrumentation type:', type);
}
}
exports.addConsoleInstrumentationHandler = console.addConsoleInstrumentationHandler;
exports.addClickKeypressInstrumentationHandler = dom.addClickKeypressInstrumentationHandler;
exports.addFetchInstrumentationHandler = fetch.addFetchInstrumentationHandler;
exports.addGlobalErrorInstrumentationHandler = globalError.addGlobalErrorInstrumentationHandler;
exports.addGlobalUnhandledRejectionInstrumentationHandler = globalUnhandledRejection.addGlobalUnhandledRejectionInstrumentationHandler;
exports.addHistoryInstrumentationHandler = history.addHistoryInstrumentationHandler;
exports.SENTRY_XHR_DATA_KEY = xhr.SENTRY_XHR_DATA_KEY;
exports.addXhrInstrumentationHandler = xhr.addXhrInstrumentationHandler;
exports.addInstrumentationHandler = addInstrumentationHandler;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sources":["../../../src/instrument/index.ts"],"sourcesContent":["// TODO(v8): Consider moving this file (or at least parts of it) into the browser package. The registered handlers are mostly non-generic and we risk leaking runtime specific code into generic packages.\n\nimport { DEBUG_BUILD } from '../debug-build';\nimport { logger } from './../logger';\nimport type {\n InstrumentHandlerCallback as _InstrumentHandlerCallback,\n InstrumentHandlerType as _InstrumentHandlerType,\n} from './_handlers';\nimport { resetInstrumentationHandlers } from './_handlers';\nimport { addConsoleInstrumentationHandler } from './console';\nimport { addClickKeypressInstrumentationHandler } from './dom';\nimport { addFetchInstrumentationHandler } from './fetch';\nimport { addGlobalErrorInstrumentationHandler } from './globalError';\nimport { addGlobalUnhandledRejectionInstrumentationHandler } from './globalUnhandledRejection';\nimport { addHistoryInstrumentationHandler } from './history';\nimport { SENTRY_XHR_DATA_KEY, addXhrInstrumentationHandler } from './xhr';\n\n/**\n * Add handler that will be called when given type of instrumentation triggers.\n * Use at your own risk, this might break without changelog notice, only used internally.\n * @hidden\n * @deprecated Use the proper function per instrumentation type instead!\n */\nexport function addInstrumentationHandler(type: _InstrumentHandlerType, callback: _InstrumentHandlerCallback): void {\n switch (type) {\n case 'console':\n return addConsoleInstrumentationHandler(callback);\n case 'dom':\n return addClickKeypressInstrumentationHandler(callback);\n case 'xhr':\n return addXhrInstrumentationHandler(callback);\n case 'fetch':\n return addFetchInstrumentationHandler(callback);\n case 'history':\n return addHistoryInstrumentationHandler(callback);\n case 'error':\n return addGlobalErrorInstrumentationHandler(callback);\n case 'unhandledrejection':\n return addGlobalUnhandledRejectionInstrumentationHandler(callback);\n default:\n DEBUG_BUILD && logger.warn('unknown instrumentation type:', type);\n }\n}\n\n/**\n * @deprecated Use the specific handler data types from @sentry/types instead, e.g. HandlerDataFetch, HandlerDataConsole, ...\n */\ntype InstrumentHandlerCallback = _InstrumentHandlerCallback;\n\n/**\n * @deprecated Use the specific handler functions instead, e.g. addConsoleInstrumentationHandler, ...\n */\ntype InstrumentHandlerType = _InstrumentHandlerType;\n\n// eslint-disable-next-line deprecation/deprecation\nexport type { InstrumentHandlerCallback, InstrumentHandlerType };\n\nexport {\n addConsoleInstrumentationHandler,\n addClickKeypressInstrumentationHandler,\n addXhrInstrumentationHandler,\n addFetchInstrumentationHandler,\n addHistoryInstrumentationHandler,\n addGlobalErrorInstrumentationHandler,\n addGlobalUnhandledRejectionInstrumentationHandler,\n SENTRY_XHR_DATA_KEY,\n // Only exported for tests\n resetInstrumentationHandlers,\n};\n"],"names":["addConsoleInstrumentationHandler","addClickKeypressInstrumentationHandler","addXhrInstrumentationHandler","addFetchInstrumentationHandler","addHistoryInstrumentationHandler","addGlobalErrorInstrumentationHandler","addGlobalUnhandledRejectionInstrumentationHandler","DEBUG_BUILD","logger"],"mappings":";;;;;;;;;;;;AAAA;AAgBA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,yBAAyB,CAAC,IAAI,EAA0B,QAAQ,EAAoC;AACpH,EAAE,QAAQ,IAAI;AACd,IAAI,KAAK,SAAS;AAClB,MAAM,OAAOA,wCAAgC,CAAC,QAAQ,CAAC,CAAA;AACvD,IAAI,KAAK,KAAK;AACd,MAAM,OAAOC,0CAAsC,CAAC,QAAQ,CAAC,CAAA;AAC7D,IAAI,KAAK,KAAK;AACd,MAAM,OAAOC,gCAA4B,CAAC,QAAQ,CAAC,CAAA;AACnD,IAAI,KAAK,OAAO;AAChB,MAAM,OAAOC,oCAA8B,CAAC,QAAQ,CAAC,CAAA;AACrD,IAAI,KAAK,SAAS;AAClB,MAAM,OAAOC,wCAAgC,CAAC,QAAQ,CAAC,CAAA;AACvD,IAAI,KAAK,OAAO;AAChB,MAAM,OAAOC,gDAAoC,CAAC,QAAQ,CAAC,CAAA;AAC3D,IAAI,KAAK,oBAAoB;AAC7B,MAAM,OAAOC,0EAAiD,CAAC,QAAQ,CAAC,CAAA;AACxE,IAAI;AACJ,MAAMC,sBAAA,IAAeC,aAAM,CAAC,IAAI,CAAC,+BAA+B,EAAE,IAAI,CAAC,CAAA;AACvE,GAAE;AACF;;;;;;;;;;;;"}

161
node_modules/@sentry/utils/cjs/instrument/xhr.js generated vendored Normal file
View File

@@ -0,0 +1,161 @@
Object.defineProperty(exports, '__esModule', { value: true });
const is = require('../is.js');
const object = require('../object.js');
const worldwide = require('../worldwide.js');
const _handlers = require('./_handlers.js');
const WINDOW = worldwide.GLOBAL_OBJ ;
const SENTRY_XHR_DATA_KEY = '__sentry_xhr_v3__';
/**
* Add an instrumentation handler for when an XHR request happens.
* The handler function is called once when the request starts and once when it ends,
* which can be identified by checking if it has an `endTimestamp`.
*
* Use at your own risk, this might break without changelog notice, only used internally.
* @hidden
*/
function addXhrInstrumentationHandler(handler) {
const type = 'xhr';
_handlers.addHandler(type, handler);
_handlers.maybeInstrument(type, instrumentXHR);
}
/** Exported only for tests. */
function instrumentXHR() {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if (!(WINDOW ).XMLHttpRequest) {
return;
}
const xhrproto = XMLHttpRequest.prototype;
object.fill(xhrproto, 'open', function (originalOpen) {
return function ( ...args) {
const startTimestamp = Date.now();
// open() should always be called with two or more arguments
// But to be on the safe side, we actually validate this and bail out if we don't have a method & url
const method = is.isString(args[0]) ? args[0].toUpperCase() : undefined;
const url = parseUrl(args[1]);
if (!method || !url) {
return originalOpen.apply(this, args);
}
this[SENTRY_XHR_DATA_KEY] = {
method,
url,
request_headers: {},
};
// if Sentry key appears in URL, don't capture it as a request
if (method === 'POST' && url.match(/sentry_key/)) {
this.__sentry_own_request__ = true;
}
const onreadystatechangeHandler = () => {
// For whatever reason, this is not the same instance here as from the outer method
const xhrInfo = this[SENTRY_XHR_DATA_KEY];
if (!xhrInfo) {
return;
}
if (this.readyState === 4) {
try {
// touching statusCode in some platforms throws
// an exception
xhrInfo.status_code = this.status;
} catch (e) {
/* do nothing */
}
const handlerData = {
args: [method, url],
endTimestamp: Date.now(),
startTimestamp,
xhr: this,
};
_handlers.triggerHandlers('xhr', handlerData);
}
};
if ('onreadystatechange' in this && typeof this.onreadystatechange === 'function') {
object.fill(this, 'onreadystatechange', function (original) {
return function ( ...readyStateArgs) {
onreadystatechangeHandler();
return original.apply(this, readyStateArgs);
};
});
} else {
this.addEventListener('readystatechange', onreadystatechangeHandler);
}
// Intercepting `setRequestHeader` to access the request headers of XHR instance.
// This will only work for user/library defined headers, not for the default/browser-assigned headers.
// Request cookies are also unavailable for XHR, as `Cookie` header can't be defined by `setRequestHeader`.
object.fill(this, 'setRequestHeader', function (original) {
return function ( ...setRequestHeaderArgs) {
const [header, value] = setRequestHeaderArgs;
const xhrInfo = this[SENTRY_XHR_DATA_KEY];
if (xhrInfo && is.isString(header) && is.isString(value)) {
xhrInfo.request_headers[header.toLowerCase()] = value;
}
return original.apply(this, setRequestHeaderArgs);
};
});
return originalOpen.apply(this, args);
};
});
object.fill(xhrproto, 'send', function (originalSend) {
return function ( ...args) {
const sentryXhrData = this[SENTRY_XHR_DATA_KEY];
if (!sentryXhrData) {
return originalSend.apply(this, args);
}
if (args[0] !== undefined) {
sentryXhrData.body = args[0];
}
const handlerData = {
args: [sentryXhrData.method, sentryXhrData.url],
startTimestamp: Date.now(),
xhr: this,
};
_handlers.triggerHandlers('xhr', handlerData);
return originalSend.apply(this, args);
};
});
}
function parseUrl(url) {
if (is.isString(url)) {
return url;
}
try {
// url can be a string or URL
// but since URL is not available in IE11, we do not check for it,
// but simply assume it is an URL and return `toString()` from it (which returns the full URL)
// If that fails, we just return undefined
return (url ).toString();
} catch (e2) {} // eslint-disable-line no-empty
return undefined;
}
exports.SENTRY_XHR_DATA_KEY = SENTRY_XHR_DATA_KEY;
exports.addXhrInstrumentationHandler = addXhrInstrumentationHandler;
exports.instrumentXHR = instrumentXHR;
//# sourceMappingURL=xhr.js.map

1
node_modules/@sentry/utils/cjs/instrument/xhr.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long