Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
}
};
});
});
}
public setupOnce(): void {
this._ignoreOnError = this._ignoreOnError;
const global = getGlobalObject();
fill(global, 'setTimeout', this._wrapTimeFunction.bind(this));
fill(global, 'setInterval', this._wrapTimeFunction.bind(this));
fill(global, 'requestAnimationFrame', this._wrapRAF.bind(this));
if ('XMLHttpRequest' in global) {
fill(XMLHttpRequest.prototype, 'send', this._wrapXHR.bind(this));
}
[
'EventTarget',
'Window',
'Node',
'ApplicationCache',
'AudioTrackList',
'ChannelMergerNode',
'CryptoOperation',
'EventSource',
public setupOnce(): void {
this._ignoreOnError = this._ignoreOnError;
const global = getGlobalObject();
fill(global, 'setTimeout', this._wrapTimeFunction.bind(this));
fill(global, 'setInterval', this._wrapTimeFunction.bind(this));
fill(global, 'requestAnimationFrame', this._wrapRAF.bind(this));
if ('XMLHttpRequest' in global) {
fill(XMLHttpRequest.prototype, 'send', this._wrapXHR.bind(this));
}
[
'EventTarget',
'Window',
'Node',
'ApplicationCache',
'AudioTrackList',
'ChannelMergerNode',
'CryptoOperation',
'EventSource',
'FileReader',
'HTMLUnknownElement',
'IDBDatabase',
'IDBRequest',
'IDBTransaction',
function wrapProp(prop: XMLHttpRequestProp, xhr: XMLHttpRequest): void {
if (prop in xhr && typeof xhr[prop] === 'function') {
fill(xhr, prop, original =>
wrap(original, {
mechanism: {
data: {
function: prop,
handler: (original && original.name) || '',
},
handled: true,
type: 'instrument',
},
}),
);
}
}
return function(level: string): any {
if (!(level in originalModule)) {
return;
}
fill(originalModule, level, function(originalConsoleLevel: () => any): any {
let sentryLevel: Severity;
switch (level) {
case 'debug':
sentryLevel = Severity.Debug;
break;
case 'error':
sentryLevel = Severity.Error;
break;
case 'info':
sentryLevel = Severity.Info;
break;
case 'warn':
sentryLevel = Severity.Warning;
break;
default: