Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function consoleBreadcrumb(handlerData: { [key: string]: any }): void {
const breadcrumb = {
category: 'console',
data: {
extra: {
arguments: normalize(handlerData.args, 3),
},
logger: 'console',
},
level: Severity.fromString(handlerData.level),
message: safeJoin(handlerData.args, ' '),
};
if (handlerData.level === 'assert') {
if (handlerData.args[0] === false) {
breadcrumb.message = `Assertion failed: ${safeJoin(handlerData.args.slice(1), ' ') || 'console.assert'}`;
breadcrumb.data.extra.arguments = normalize(handlerData.args.slice(1), 3);
} else {
// Don't capture a breadcrumb for passed assertions
return;
}
}
const breadcrumb = {
category: 'console',
data: {
extra: {
arguments: normalize(handlerData.args, 3),
},
logger: 'console',
},
level: Severity.fromString(handlerData.level),
message: safeJoin(handlerData.args, ' '),
};
if (handlerData.level === 'assert') {
if (handlerData.args[0] === false) {
breadcrumb.message = `Assertion failed: ${safeJoin(handlerData.args.slice(1), ' ') || 'console.assert'}`;
breadcrumb.data.extra.arguments = normalize(handlerData.args.slice(1), 3);
} else {
// Don't capture a breadcrumb for passed assertions
return;
}
}
getCurrentHub().addBreadcrumb(breadcrumb, {
input: handlerData.args,
level: handlerData.level,
});
}
fill(
xhrproto,
'open',
originalOpen =>
function(this: XMLHttpRequest, ...args: any[]): void {
// @ts-ignore
const self = getCurrentHub().getIntegration(Tracing);
if (self) {
self._xhrUrl = args[1] as string;
}
// tslint:disable-next-line: no-unsafe-any
return originalOpen.apply(this, args);
},
);
fill(
xhrproto,
'send',
originalSend =>
function(this: XMLHttpRequest, ...args: any[]): void {
// @ts-ignore
const self = getCurrentHub().getIntegration(Tracing);
if (self && self._xhrUrl && self._options.tracingOrigins) {
const url = self._xhrUrl;
const headers = getCurrentHub().traceHeaders();
// tslint:disable-next-line: prefer-for-of
const isWhitelisted = self._options.tracingOrigins.some((origin: string | RegExp) =>
isMatchingPattern(url, origin),
);
if (isWhitelisted && this.setRequestHeader) {
Object.keys(headers).forEach(key => {
if (url) {
// coerce to string (this is what pushState does)
const to = String(url);
const handlerData = {
from: lastHref,
to,
};
// keep track of the current URL state, as we always receive only the updated state
lastHref = to;
triggerHandlers(handlerData);
}
return originalHistoryFunction.apply(this, args);
};
}
fill(global.history, 'pushState', historyReplacementFunction);
fill(global.history, 'replaceState', historyReplacementFunction);
}
public setupOnce(): void {
const nativeModule = require('module');
fill(nativeModule, '_load', loadWrapper(nativeModule));
// special case: since console is built-in and app-level code won't require() it, do that here
require('console');
}
}
private _traceXHR(getCurrentHub: () => Hub): void {
if (!('XMLHttpRequest' in getGlobalObject())) {
return;
}
const xhrproto = XMLHttpRequest.prototype;
fill(
xhrproto,
'open',
originalOpen =>
function(this: XMLHttpRequest, ...args: any[]): void {
// @ts-ignore
const self = getCurrentHub().getIntegration(Tracing);
if (self) {
self._xhrUrl = args[1] as string;
}
// tslint:disable-next-line: no-unsafe-any
return originalOpen.apply(this, args);
},
);
fill(
xhrproto,
['debug', 'info', 'warn', 'error', 'log', 'assert'].forEach(function(level: string): void {
if (!(level in global.console)) {
return;
}
fill(global.console, level, function(originalConsoleLevel: () => any): Function {
return function(...args: any[]): void {
const handlerData = {
args,
level,
};
triggerHandlers(handlerData);
// this fails for some browsers. :(
if (originalConsoleLevel) {
Function.prototype.apply.call(originalConsoleLevel, global.console, args);
}
};
});
});
}
private _traceFetch(getCurrentHub: () => Hub): void {
if (!supportsNativeFetch()) {
return;
}
// tslint:disable: only-arrow-functions
fill(getGlobalObject(), 'fetch', function(originalFetch: () => void): () => void {
return function(...args: any[]): void {
// @ts-ignore
const self = getCurrentHub().getIntegration(Tracing);
if (self && self._options.tracingOrigins) {
const url = args[0] as string;
const options = (args[1] = (args[1] as { [key: string]: any }) || {});
let whiteListed = false;
self._options.tracingOrigins.forEach((whiteListUrl: string | RegExp) => {
if (!whiteListed) {
whiteListed = isMatchingPattern(url, whiteListUrl);
}
});
if (whiteListed) {
if (options.headers) {
public showReportDialog(options: ReportDialogOptions = {}): void {
// doesn't work without a document (React Native)
const document = getGlobalObject().document;
if (!document) {
return;
}
if (!this._isEnabled()) {
logger.error('Trying to call showReportDialog with Sentry Client is disabled');
return;
}
const dsn = options.dsn || this.getDsn();
if (!options.eventId) {
logger.error('Missing `eventId` option in showReportDialog call');
return;
}
public constructor(options: { Ember?: any } = {}) {
// tslint:disable-next-line: no-unsafe-any
this._Ember = options.Ember || getGlobalObject().Ember;
}