@sentry/browser 6.13.2 → 6.14.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/bundle.es6.js +455 -354
- package/build/bundle.es6.js.map +1 -1
- package/build/bundle.es6.min.js +2 -2
- package/build/bundle.es6.min.js.map +1 -1
- package/build/bundle.js +456 -356
- package/build/bundle.js.map +1 -1
- package/build/bundle.min.js +2 -2
- package/build/bundle.min.js.map +1 -1
- package/dist/eventbuilder.d.ts.map +1 -1
- package/dist/eventbuilder.js +3 -7
- package/dist/eventbuilder.js.map +1 -1
- package/dist/integrations/trycatch.js +1 -1
- package/dist/integrations/trycatch.js.map +1 -1
- package/dist/transports/base.d.ts.map +1 -1
- package/dist/transports/base.js +8 -6
- package/dist/transports/base.js.map +1 -1
- package/dist/transports/fetch.d.ts +1 -2
- package/dist/transports/fetch.d.ts.map +1 -1
- package/dist/transports/fetch.js +2 -67
- package/dist/transports/fetch.js.map +1 -1
- package/dist/transports/utils.d.ts +48 -0
- package/dist/transports/utils.d.ts.map +1 -0
- package/dist/transports/utils.js +99 -0
- package/dist/transports/utils.js.map +1 -0
- package/dist/transports/xhr.js +1 -1
- package/dist/transports/xhr.js.map +1 -1
- package/esm/eventbuilder.d.ts.map +1 -1
- package/esm/eventbuilder.js +3 -7
- package/esm/eventbuilder.js.map +1 -1
- package/esm/integrations/trycatch.js +1 -1
- package/esm/integrations/trycatch.js.map +1 -1
- package/esm/transports/base.d.ts.map +1 -1
- package/esm/transports/base.js +9 -7
- package/esm/transports/base.js.map +1 -1
- package/esm/transports/fetch.d.ts +1 -2
- package/esm/transports/fetch.d.ts.map +1 -1
- package/esm/transports/fetch.js +2 -67
- package/esm/transports/fetch.js.map +1 -1
- package/esm/transports/utils.d.ts +48 -0
- package/esm/transports/utils.d.ts.map +1 -0
- package/esm/transports/utils.js +96 -0
- package/esm/transports/utils.js.map +1 -0
- package/esm/transports/xhr.js +1 -1
- package/esm/transports/xhr.js.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BAAgB,CAAC,MAAM,EAAE,KAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;qBAChE;iBACF;gBACD,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;YACnC,CAAC,CAAC;QApBF,CAoBE,CACL;aACA,IAAI,CAAC,SAAS,EAAE,UAAA,MAAM;YACrB,gGAAgG;YAChG,IAAI,MAAM,YAAY,mBAAW,EAAE;gBACjC,KAAI,CAAC,eAAe,CAAC,eAAO,CAAC,aAAa,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC;aACjE;iBAAM;gBACL,KAAI,CAAC,eAAe,CAAC,eAAO,CAAC,YAAY,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC;aAChE;YACD,MAAM,MAAM,CAAC;QACf,CAAC,CAAC,CAAC;IACP,CAAC;IACH,mBAAC;AAAD,CAAC,AApED,CAAkC,oBAAa,GAoE9C;AApEY,oCAAY","sourcesContent":["import { eventToSentryRequest, sessionToSentryRequest } from '@sentry/core';\nimport { Event, Outcome, Response, SentryRequest, Session } from '@sentry/types';\nimport { SentryError, SyncPromise } from '@sentry/utils';\n\nimport { BaseTransport } from './base';\n\n/** `XHR` based transport */\nexport class XHRTransport extends BaseTransport {\n /**\n * @inheritDoc\n */\n public sendEvent(event: Event): PromiseLike<Response> {\n return this._sendRequest(eventToSentryRequest(event, this._api), event);\n }\n\n /**\n * @inheritDoc\n */\n public sendSession(session: Session): PromiseLike<Response> {\n return this._sendRequest(sessionToSentryRequest(session, this._api), session);\n }\n\n /**\n * @param sentryRequest Prepared SentryRequest to be delivered\n * @param originalPayload Original payload used to create SentryRequest\n */\n private _sendRequest(sentryRequest: SentryRequest, originalPayload: Event | Session): PromiseLike<Response> {\n if (this._isRateLimited(sentryRequest.type)) {\n this.recordLostEvent(Outcome.RateLimitBackoff, sentryRequest.type);\n\n return Promise.reject({\n event: originalPayload,\n type: sentryRequest.type,\n reason: `Transport for ${sentryRequest.type} requests locked till ${this._disabledUntil(\n sentryRequest.type,\n )} due to too many requests.`,\n status: 429,\n });\n }\n\n return this._buffer\n .add(\n () =>\n new SyncPromise<Response>((resolve, reject) => {\n const request = new XMLHttpRequest();\n\n request.onreadystatechange = (): void => {\n if (request.readyState === 4) {\n const headers = {\n 'x-sentry-rate-limits': request.getResponseHeader('X-Sentry-Rate-Limits'),\n 'retry-after': request.getResponseHeader('Retry-After'),\n };\n this._handleResponse({ requestType: sentryRequest.type, response: request, headers, resolve, reject });\n }\n };\n\n request.open('POST', sentryRequest.url);\n for (const header in this.options.headers) {\n if (Object.prototype.hasOwnProperty.call(this.options.headers, header)) {\n request.setRequestHeader(header, this.options.headers[header]);\n }\n }\n request.send(sentryRequest.body);\n }),\n )\n .then(undefined, reason => {\n // It's either buffer rejection or any other xhr/fetch error, which are treated as NetworkError.\n if (reason instanceof SentryError) {\n this.recordLostEvent(Outcome.QueueOverflow, sentryRequest.type);\n } else {\n this.recordLostEvent(Outcome.NetworkError, sentryRequest.type);\n }\n throw reason;\n });\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eventbuilder.d.ts","sourceRoot":"","sources":["../src/eventbuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAgBpE;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,SAAS,GAAG,WAAW,CAAC,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"eventbuilder.d.ts","sourceRoot":"","sources":["../src/eventbuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAgBpE;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,SAAS,GAAG,WAAW,CAAC,KAAK,CAAC,CAW7G;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,KAAK,GAAE,QAAwB,EAC/B,IAAI,CAAC,EAAE,SAAS,GACf,WAAW,CAAC,KAAK,CAAC,CAUpB;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,OAAO,EAClB,kBAAkB,CAAC,EAAE,KAAK,EAC1B,OAAO,GAAE;IACP,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CACvB,GACL,KAAK,CA4DP;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,MAAM,EACb,kBAAkB,CAAC,EAAE,KAAK,EAC1B,OAAO,GAAE;IACP,gBAAgB,CAAC,EAAE,OAAO,CAAC;CACvB,GACL,KAAK,CAcP"}
|
package/esm/eventbuilder.js
CHANGED
|
@@ -12,10 +12,7 @@ export function eventFromException(options, exception, hint) {
|
|
|
12
12
|
var event = eventFromUnknownInput(exception, syntheticException, {
|
|
13
13
|
attachStacktrace: options.attachStacktrace,
|
|
14
14
|
});
|
|
15
|
-
addExceptionMechanism(event,
|
|
16
|
-
handled: true,
|
|
17
|
-
type: 'generic',
|
|
18
|
-
});
|
|
15
|
+
addExceptionMechanism(event); // defaults to { type: 'generic', handled: true }
|
|
19
16
|
event.level = Severity.Error;
|
|
20
17
|
if (hint && hint.event_id) {
|
|
21
18
|
event.event_id = hint.event_id;
|
|
@@ -44,11 +41,10 @@ export function eventFromMessage(options, message, level, hint) {
|
|
|
44
41
|
export function eventFromUnknownInput(exception, syntheticException, options) {
|
|
45
42
|
if (options === void 0) { options = {}; }
|
|
46
43
|
var event;
|
|
47
|
-
if (isErrorEvent(exception)
|
|
44
|
+
if (isErrorEvent(exception)) {
|
|
48
45
|
// If it is an ErrorEvent with `error` property, extract it to get actual Error
|
|
49
|
-
var errorEvent = exception;
|
|
50
46
|
// eslint-disable-next-line no-param-reassign
|
|
51
|
-
exception =
|
|
47
|
+
exception = exception.error;
|
|
52
48
|
event = eventFromStacktrace(computeStackTrace(exception));
|
|
53
49
|
return event;
|
|
54
50
|
}
|
package/esm/eventbuilder.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eventbuilder.js","sourceRoot":"","sources":["../src/eventbuilder.ts"],"names":[],"mappings":";AAAA,OAAO,EAA6B,QAAQ,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,UAAU,EACV,cAAc,EACd,OAAO,EACP,YAAY,EACZ,OAAO,EACP,aAAa,EACb,WAAW,GACZ,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAC7F,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAgB,EAAE,SAAkB,EAAE,IAAgB;IACvF,IAAM,kBAAkB,GAAG,CAAC,IAAI,IAAI,IAAI,CAAC,kBAAkB,CAAC,IAAI,SAAS,CAAC;IAC1E,IAAM,KAAK,GAAG,qBAAqB,CAAC,SAAS,EAAE,kBAAkB,EAAE;QACjE,gBAAgB,EAAE,OAAO,CAAC,gBAAgB;KAC3C,CAAC,CAAC;IACH,qBAAqB,CAAC,KAAK,
|
|
1
|
+
{"version":3,"file":"eventbuilder.js","sourceRoot":"","sources":["../src/eventbuilder.ts"],"names":[],"mappings":";AAAA,OAAO,EAA6B,QAAQ,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,UAAU,EACV,cAAc,EACd,OAAO,EACP,YAAY,EACZ,OAAO,EACP,aAAa,EACb,WAA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AAK,CAAC;AACf,CAAC","sourcesContent":["import { Event, EventHint, Options, Severity } from '@sentry/types';\nimport {\n addExceptionMechanism,\n addExceptionTypeValue,\n isDOMError,\n isDOMException,\n isError,\n isErrorEvent,\n isEvent,\n isPlainObject,\n SyncPromise,\n} from '@sentry/utils';\n\nimport { eventFromPlainObject, eventFromStacktrace, prepareFramesForEvent } from './parsers';\nimport { computeStackTrace } from './tracekit';\n\n/**\n * Builds and Event from a Exception\n * @hidden\n */\nexport function eventFromException(options: Options, exception: unknown, hint?: EventHint): PromiseLike<Event> {\n const syntheticException = (hint && hint.syntheticException) || undefined;\n const event = eventFromUnknownInput(exception, syntheticException, {\n attachStacktrace: options.attachStacktrace,\n });\n addExceptionMechanism(event); // defaults to { type: 'generic', handled: true }\n event.level = Severity.Error;\n if (hint && hint.event_id) {\n event.event_id = hint.event_id;\n }\n return SyncPromise.resolve(event);\n}\n\n/**\n * Builds and Event from a Message\n * @hidden\n */\nexport function eventFromMessage(\n options: Options,\n message: string,\n level: Severity = Severity.Info,\n hint?: EventHint,\n): PromiseLike<Event> {\n const syntheticException = (hint && hint.syntheticException) || undefined;\n const event = eventFromString(message, syntheticException, {\n attachStacktrace: options.attachStacktrace,\n });\n event.level = level;\n if (hint && hint.event_id) {\n event.event_id = hint.event_id;\n }\n return SyncPromise.resolve(event);\n}\n\n/**\n * @hidden\n */\nexport function eventFromUnknownInput(\n exception: unknown,\n syntheticException?: Error,\n options: {\n rejection?: boolean;\n attachStacktrace?: boolean;\n } = {},\n): Event {\n let event: Event;\n\n if (isErrorEvent(exception)) {\n // If it is an ErrorEvent with `error` property, extract it to get actual Error\n // eslint-disable-next-line no-param-reassign\n exception = exception.error;\n event = eventFromStacktrace(computeStackTrace(exception));\n return event;\n }\n if (isDOMError(exception) || isDOMException(exception)) {\n // If it is a DOMError or DOMException (which are legacy APIs, but still supported in some browsers)\n // then we just extract the name, code, and message, as they don't provide anything else\n // https://developer.mozilla.org/en-US/docs/Web/API/DOMError\n // https://developer.mozilla.org/en-US/docs/Web/API/DOMException\n const domException = exception as DOMException;\n const name = domException.name || (isDOMError(domException) ? 'DOMError' : 'DOMException');\n const message = domException.message ? `${name}: ${domException.message}` : name;\n\n event = eventFromString(message, syntheticException, options);\n addExceptionTypeValue(event, message);\n if ('code' in domException) {\n event.tags = { ...event.tags, 'DOMException.code': `${domException.code}` };\n }\n\n return event;\n }\n if (isError(exception)) {\n // we have a real Error object, do nothing\n event = eventFromStacktrace(computeStackTrace(exception));\n return event;\n }\n if (isPlainObject(exception) || isEvent(exception)) {\n // If it is plain Object or Event, serialize it manually and extract options\n // This will allow us to group events based on top-level keys\n // which is much better than creating new group when any key/value change\n const objectException = exception as Record<string, unknown>;\n event = eventFromPlainObject(objectException, syntheticException, options.rejection);\n addExceptionMechanism(event, {\n synthetic: true,\n });\n return event;\n }\n\n // If none of previous checks were valid, then it means that it's not:\n // - an instance of DOMError\n // - an instance of DOMException\n // - an instance of Event\n // - an instance of Error\n // - a valid ErrorEvent (one with an error property)\n // - a plain Object\n //\n // So bail out and capture it as a simple message:\n event = eventFromString(exception as string, syntheticException, options);\n addExceptionTypeValue(event, `${exception}`, undefined);\n addExceptionMechanism(event, {\n synthetic: true,\n });\n\n return event;\n}\n\n/**\n * @hidden\n */\nexport function eventFromString(\n input: string,\n syntheticException?: Error,\n options: {\n attachStacktrace?: boolean;\n } = {},\n): Event {\n const event: Event = {\n message: input,\n };\n\n if (options.attachStacktrace && syntheticException) {\n const stacktrace = computeStackTrace(syntheticException);\n const frames = prepareFramesForEvent(stacktrace.stack);\n event.stacktrace = {\n frames,\n };\n }\n\n return event;\n}\n"]}
|
|
@@ -110,7 +110,7 @@ var TryCatch = /** @class */ (function () {
|
|
|
110
110
|
var global = getGlobalObject();
|
|
111
111
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
112
112
|
var proto = global[target] && global[target].prototype;
|
|
113
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
113
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, no-prototype-builtins
|
|
114
114
|
if (!proto || !proto.hasOwnProperty || !proto.hasOwnProperty('addEventListener')) {
|
|
115
115
|
return;
|
|
116
116
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trycatch.js","sourceRoot":"","sources":["../../src/integrations/trycatch.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEvE,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,IAAM,oBAAoB,GAAG;IAC3B,aAAa;IACb,QAAQ;IACR,MAAM;IACN,kBAAkB;IAClB,gBAAgB;IAChB,mBAAmB;IACnB,iBAAiB;IACjB,aAAa;IACb,YAAY;IACZ,oBAAoB;IACpB,aAAa;IACb,YAAY;IACZ,gBAAgB;IAChB,cAAc;IACd,iBAAiB;IACjB,aAAa;IACb,aAAa;IACb,cAAc;IACd,oBAAoB;IACpB,QAAQ;IACR,WAAW;IACX,cAAc;IACd,eAAe;IACf,WAAW;IACX,iBAAiB;IACjB,QAAQ;IACR,gBAAgB;IAChB,2BAA2B;IAC3B,sBAAsB;CACvB,CAAC;AAaF,0FAA0F;AAC1F;IAcE;;OAEG;IACH,kBAAmB,OAAkC;QAXrD;;WAEG;QACI,SAAI,GAAW,QAAQ,CAAC,EAAE,CAAC;QAShC,IAAI,CAAC,QAAQ,cACX,cAAc,EAAE,IAAI,EACpB,WAAW,EAAE,IAAI,EACjB,qBAAqB,EAAE,IAAI,EAC3B,WAAW,EAAE,IAAI,EACjB,UAAU,EAAE,IAAI,IACb,OAAO,CACX,CAAC;IACJ,CAAC;IAED;;;OAGG;IACI,4BAAS,GAAhB;QACE,IAAM,MAAM,GAAG,eAAe,EAAE,CAAC;QAEjC,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE;YAC5B,IAAI,CAAC,MAAM,EAAE,YAAY,EAAE,IAAI,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';\nimport { fill, getFunctionName, getGlobalObject } from '@sentry/utils';\n\nimport { wrap } from '../helpers';\n\nconst DEFAULT_EVENT_TARGET = [\n 'EventTarget',\n 'Window',\n 'Node',\n 'ApplicationCache',\n 'AudioTrackList',\n 'ChannelMergerNode',\n 'CryptoOperation',\n 'EventSource',\n 'FileReader',\n 'HTMLUnknownElement',\n 'IDBDatabase',\n 'IDBRequest',\n 'IDBTransaction',\n 'KeyOperation',\n 'MediaController',\n 'MessagePort',\n 'ModalWindow',\n 'Notification',\n 'SVGElementInstance',\n 'Screen',\n 'TextTrack',\n 'TextTrackCue',\n 'TextTrackList',\n 'WebSocket',\n 'WebSocketWorker',\n 'Worker',\n 'XMLHttpRequest',\n 'XMLHttpRequestEventTarget',\n 'XMLHttpRequestUpload',\n];\n\ntype XMLHttpRequestProp = 'onload' | 'onerror' | 'onprogress' | 'onreadystatechange';\n\n/** JSDoc */\ninterface TryCatchOptions {\n setTimeout: boolean;\n setInterval: boolean;\n requestAnimationFrame: boolean;\n XMLHttpRequest: boolean;\n eventTarget: boolean | string[];\n}\n\n/** Wrap timer functions and event targets to catch errors and provide better meta data */\nexport class TryCatch implements Integration {\n /**\n * @inheritDoc\n */\n public static id: string = 'TryCatch';\n\n /**\n * @inheritDoc\n */\n public name: string = TryCatch.id;\n\n /** JSDoc */\n private readonly _options: TryCatchOptions;\n\n /**\n * @inheritDoc\n */\n public constructor(options?: Partial<TryCatchOptions>) {\n this._options = {\n XMLHttpRequest: true,\n eventTarget: true,\n requestAnimationFrame: true,\n setInterval: true,\n setTimeout: true,\n ...options,\n };\n }\n\n /**\n * Wrap timer functions and event targets to catch errors\n * and provide better metadata.\n */\n public setupOnce(): void {\n const global = getGlobalObject();\n\n if (this._options.setTimeout) {\n fill(global, 'setTimeout', this._wrapTimeFunction.bind(this));\n }\n\n if (this._options.setInterval) {\n fill(global, 'setInterval', this._wrapTimeFunction.bind(this));\n }\n\n if (this._options.requestAnimationFrame) {\n fill(global, 'requestAnimationFrame', this._wrapRAF.bind(this));\n }\n\n if (this._options.XMLHttpRequest && 'XMLHttpRequest' in global) {\n fill(XMLHttpRequest.prototype, 'send', this._wrapXHR.bind(this));\n }\n\n if (this._options.eventTarget) {\n const eventTarget = Array.isArray(this._options.eventTarget) ? this._options.eventTarget : DEFAULT_EVENT_TARGET;\n eventTarget.forEach(this._wrapEventTarget.bind(this));\n }\n }\n\n /** JSDoc */\n private _wrapTimeFunction(original: () => void): () => number {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return function(this: any, ...args: any[]): number {\n const originalCallback = args[0];\n args[0] = wrap(originalCallback, {\n mechanism: {\n data: { function: getFunctionName(original) },\n handled: true,\n type: 'instrument',\n },\n });\n return original.apply(this, args);\n };\n }\n\n /** JSDoc */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private _wrapRAF(original: any): (callback: () => void) => any {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return function(this: any, callback: () => void): () => void {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return original.call(\n this,\n wrap(callback, {\n mechanism: {\n data: {\n function: 'requestAnimationFrame',\n handler: getFunctionName(original),\n },\n handled: true,\n type: 'instrument',\n },\n }),\n );\n };\n }\n\n /** JSDoc */\n private _wrapEventTarget(target: string): void {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const global = getGlobalObject() as { [key: string]: any };\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const proto = global[target] && global[target].prototype;\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n if (!proto || !proto.hasOwnProperty || !proto.hasOwnProperty('addEventListener')) {\n return;\n }\n\n fill(proto, 'addEventListener', function(\n original: () => void,\n ): (eventName: string, fn: EventListenerObject, options?: boolean | AddEventListenerOptions) => void {\n return function(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this: any,\n eventName: string,\n fn: EventListenerObject,\n options?: boolean | AddEventListenerOptions,\n ): (eventName: string, fn: EventListenerObject, capture?: boolean, secure?: boolean) => void {\n try {\n if (typeof fn.handleEvent === 'function') {\n fn.handleEvent = wrap(fn.handleEvent.bind(fn), {\n mechanism: {\n data: {\n function: 'handleEvent',\n handler: getFunctionName(fn),\n target,\n },\n handled: true,\n type: 'instrument',\n },\n });\n }\n } catch (err) {\n // can sometimes get 'Permission denied to access property \"handle Event'\n }\n\n return original.call(\n this,\n eventName,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n wrap((fn as any) as WrappedFunction, {\n mechanism: {\n data: {\n function: 'addEventListener',\n handler: getFunctionName(fn),\n target,\n },\n handled: true,\n type: 'instrument',\n },\n }),\n options,\n );\n };\n });\n\n fill(proto, 'removeEventListener', function(\n originalRemoveEventListener: () => void,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ): (this: any, eventName: string, fn: EventListenerObject, options?: boolean | EventListenerOptions) => () => void {\n return function(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this: any,\n eventName: string,\n fn: EventListenerObject,\n options?: boolean | EventListenerOptions,\n ): () => void {\n /**\n * There are 2 possible scenarios here:\n *\n * 1. Someone passes a callback, which was attached prior to Sentry initialization, or by using unmodified\n * method, eg. `document.addEventListener.call(el, name, handler). In this case, we treat this function\n * as a pass-through, and call original `removeEventListener` with it.\n *\n * 2. Someone passes a callback, which was attached after Sentry was initialized, which means that it was using\n * our wrapped version of `addEventListener`, which internally calls `wrap` helper.\n * This helper \"wraps\" whole callback inside a try/catch statement, and attached appropriate metadata to it,\n * in order for us to make a distinction between wrapped/non-wrapped functions possible.\n * If a function was wrapped, it has additional property of `__sentry_wrapped__`, holding the handler.\n *\n * When someone adds a handler prior to initialization, and then do it again, but after,\n * then we have to detach both of them. Otherwise, if we'd detach only wrapped one, it'd be impossible\n * to get rid of the initial handler and it'd stick there forever.\n */\n const wrappedEventHandler = (fn as unknown) as WrappedFunction;\n try {\n const originalEventHandler = wrappedEventHandler?.__sentry_wrapped__;\n if (originalEventHandler) {\n originalRemoveEventListener.call(this, eventName, originalEventHandler, options);\n }\n } catch (e) {\n // ignore, accessing __sentry_wrapped__ will throw in some Selenium environments\n }\n return originalRemoveEventListener.call(this, eventName, wrappedEventHandler, options);\n };\n });\n }\n\n /** JSDoc */\n private _wrapXHR(originalSend: () => void): () => void {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return function(this: XMLHttpRequest, ...args: any[]): void {\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const xhr = this;\n const xmlHttpRequestProps: XMLHttpRequestProp[] = ['onload', 'onerror', 'onprogress', 'onreadystatechange'];\n\n xmlHttpRequestProps.forEach(prop => {\n if (prop in xhr && typeof xhr[prop] === 'function') {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n fill(xhr, prop, function(original: WrappedFunction): () => any {\n const wrapOptions = {\n mechanism: {\n data: {\n function: prop,\n handler: getFunctionName(original),\n },\n handled: true,\n type: 'instrument',\n },\n };\n\n // If Instrument integration has been called before TryCatch, get the name of original function\n if (original.__sentry_original__) {\n wrapOptions.mechanism.data.handler = getFunctionName(original.__sentry_original__);\n }\n\n // Otherwise wrap directly\n return wrap(original, wrapOptions);\n });\n }\n });\n\n return originalSend.apply(this, args);\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"trycatch.js","sourceRoot":"","sources":["../../src/integrations/trycatch.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEvE,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,IAAM,oBAAoB,GAAG;IAC3B,aAAa;IACb,QAAQ;IACR,MAAM;IACN,kBAAkB;IAClB,gBAAgB;IAChB,mBAAmB;IACnB,iBAAiB;IACjB,aAAa;IACb,YAAY;IACZ,oBAAoB;IACpB,aAAa;IACb,YAAY;IACZ,gBAAgB;IAChB,cAAc;IACd,iBAAiB;IACjB,aAAa;IACb,aAAa;IACb,cAAc;IACd,oBAAoB;IACpB,QAAQ;IAC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ACnC;gCACD,OAAO,EAAE,IAAI;gCACb,IAAI,EAAE,YAAY;6BACnB;yBACF,CAAC;wBAEF,+FAA+F;wBAC/F,IAAI,QAAQ,CAAC,mBAAmB,EAAE;4BAChC,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,GAAG,eAAe,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC;yBACpF;wBAED,0BAA0B;wBAC1B,OAAO,IAAI,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;oBACrC,CAAC,CAAC,CAAC;iBACJ;YACH,CAAC,CAAC,CAAC;YAEH,OAAO,YAAY,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACxC,CAAC,CAAC;IACJ,CAAC;IAxOD;;OAEG;IACW,WAAE,GAAW,UAAU,CAAC;IAsOxC,eAAC;CAAA,AA1OD,IA0OC;SA1OY,QAAQ","sourcesContent":["import { Integration, WrappedFunction } from '@sentry/types';\nimport { fill, getFunctionName, getGlobalObject } from '@sentry/utils';\n\nimport { wrap } from '../helpers';\n\nconst DEFAULT_EVENT_TARGET = [\n 'EventTarget',\n 'Window',\n 'Node',\n 'ApplicationCache',\n 'AudioTrackList',\n 'ChannelMergerNode',\n 'CryptoOperation',\n 'EventSource',\n 'FileReader',\n 'HTMLUnknownElement',\n 'IDBDatabase',\n 'IDBRequest',\n 'IDBTransaction',\n 'KeyOperation',\n 'MediaController',\n 'MessagePort',\n 'ModalWindow',\n 'Notification',\n 'SVGElementInstance',\n 'Screen',\n 'TextTrack',\n 'TextTrackCue',\n 'TextTrackList',\n 'WebSocket',\n 'WebSocketWorker',\n 'Worker',\n 'XMLHttpRequest',\n 'XMLHttpRequestEventTarget',\n 'XMLHttpRequestUpload',\n];\n\ntype XMLHttpRequestProp = 'onload' | 'onerror' | 'onprogress' | 'onreadystatechange';\n\n/** JSDoc */\ninterface TryCatchOptions {\n setTimeout: boolean;\n setInterval: boolean;\n requestAnimationFrame: boolean;\n XMLHttpRequest: boolean;\n eventTarget: boolean | string[];\n}\n\n/** Wrap timer functions and event targets to catch errors and provide better meta data */\nexport class TryCatch implements Integration {\n /**\n * @inheritDoc\n */\n public static id: string = 'TryCatch';\n\n /**\n * @inheritDoc\n */\n public name: string = TryCatch.id;\n\n /** JSDoc */\n private readonly _options: TryCatchOptions;\n\n /**\n * @inheritDoc\n */\n public constructor(options?: Partial<TryCatchOptions>) {\n this._options = {\n XMLHttpRequest: true,\n eventTarget: true,\n requestAnimationFrame: true,\n setInterval: true,\n setTimeout: true,\n ...options,\n };\n }\n\n /**\n * Wrap timer functions and event targets to catch errors\n * and provide better metadata.\n */\n public setupOnce(): void {\n const global = getGlobalObject();\n\n if (this._options.setTimeout) {\n fill(global, 'setTimeout', this._wrapTimeFunction.bind(this));\n }\n\n if (this._options.setInterval) {\n fill(global, 'setInterval', this._wrapTimeFunction.bind(this));\n }\n\n if (this._options.requestAnimationFrame) {\n fill(global, 'requestAnimationFrame', this._wrapRAF.bind(this));\n }\n\n if (this._options.XMLHttpRequest && 'XMLHttpRequest' in global) {\n fill(XMLHttpRequest.prototype, 'send', this._wrapXHR.bind(this));\n }\n\n if (this._options.eventTarget) {\n const eventTarget = Array.isArray(this._options.eventTarget) ? this._options.eventTarget : DEFAULT_EVENT_TARGET;\n eventTarget.forEach(this._wrapEventTarget.bind(this));\n }\n }\n\n /** JSDoc */\n private _wrapTimeFunction(original: () => void): () => number {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return function(this: any, ...args: any[]): number {\n const originalCallback = args[0];\n args[0] = wrap(originalCallback, {\n mechanism: {\n data: { function: getFunctionName(original) },\n handled: true,\n type: 'instrument',\n },\n });\n return original.apply(this, args);\n };\n }\n\n /** JSDoc */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private _wrapRAF(original: any): (callback: () => void) => any {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return function(this: any, callback: () => void): () => void {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return original.call(\n this,\n wrap(callback, {\n mechanism: {\n data: {\n function: 'requestAnimationFrame',\n handler: getFunctionName(original),\n },\n handled: true,\n type: 'instrument',\n },\n }),\n );\n };\n }\n\n /** JSDoc */\n private _wrapEventTarget(target: string): void {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const global = getGlobalObject() as { [key: string]: any };\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const proto = global[target] && global[target].prototype;\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, no-prototype-builtins\n if (!proto || !proto.hasOwnProperty || !proto.hasOwnProperty('addEventListener')) {\n return;\n }\n\n fill(proto, 'addEventListener', function(\n original: () => void,\n ): (eventName: string, fn: EventListenerObject, options?: boolean | AddEventListenerOptions) => void {\n return function(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this: any,\n eventName: string,\n fn: EventListenerObject,\n options?: boolean | AddEventListenerOptions,\n ): (eventName: string, fn: EventListenerObject, capture?: boolean, secure?: boolean) => void {\n try {\n if (typeof fn.handleEvent === 'function') {\n fn.handleEvent = wrap(fn.handleEvent.bind(fn), {\n mechanism: {\n data: {\n function: 'handleEvent',\n handler: getFunctionName(fn),\n target,\n },\n handled: true,\n type: 'instrument',\n },\n });\n }\n } catch (err) {\n // can sometimes get 'Permission denied to access property \"handle Event'\n }\n\n return original.call(\n this,\n eventName,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n wrap((fn as any) as WrappedFunction, {\n mechanism: {\n data: {\n function: 'addEventListener',\n handler: getFunctionName(fn),\n target,\n },\n handled: true,\n type: 'instrument',\n },\n }),\n options,\n );\n };\n });\n\n fill(proto, 'removeEventListener', function(\n originalRemoveEventListener: () => void,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ): (this: any, eventName: string, fn: EventListenerObject, options?: boolean | EventListenerOptions) => () => void {\n return function(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this: any,\n eventName: string,\n fn: EventListenerObject,\n options?: boolean | EventListenerOptions,\n ): () => void {\n /**\n * There are 2 possible scenarios here:\n *\n * 1. Someone passes a callback, which was attached prior to Sentry initialization, or by using unmodified\n * method, eg. `document.addEventListener.call(el, name, handler). In this case, we treat this function\n * as a pass-through, and call original `removeEventListener` with it.\n *\n * 2. Someone passes a callback, which was attached after Sentry was initialized, which means that it was using\n * our wrapped version of `addEventListener`, which internally calls `wrap` helper.\n * This helper \"wraps\" whole callback inside a try/catch statement, and attached appropriate metadata to it,\n * in order for us to make a distinction between wrapped/non-wrapped functions possible.\n * If a function was wrapped, it has additional property of `__sentry_wrapped__`, holding the handler.\n *\n * When someone adds a handler prior to initialization, and then do it again, but after,\n * then we have to detach both of them. Otherwise, if we'd detach only wrapped one, it'd be impossible\n * to get rid of the initial handler and it'd stick there forever.\n */\n const wrappedEventHandler = (fn as unknown) as WrappedFunction;\n try {\n const originalEventHandler = wrappedEventHandler?.__sentry_wrapped__;\n if (originalEventHandler) {\n originalRemoveEventListener.call(this, eventName, originalEventHandler, options);\n }\n } catch (e) {\n // ignore, accessing __sentry_wrapped__ will throw in some Selenium environments\n }\n return originalRemoveEventListener.call(this, eventName, wrappedEventHandler, options);\n };\n });\n }\n\n /** JSDoc */\n private _wrapXHR(originalSend: () => void): () => void {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return function(this: XMLHttpRequest, ...args: any[]): void {\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const xhr = this;\n const xmlHttpRequestProps: XMLHttpRequestProp[] = ['onload', 'onerror', 'onprogress', 'onreadystatechange'];\n\n xmlHttpRequestProps.forEach(prop => {\n if (prop in xhr && typeof xhr[prop] === 'function') {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n fill(xhr, prop, function(original: WrappedFunction): () => any {\n const wrapOptions = {\n mechanism: {\n data: {\n function: prop,\n handler: getFunctionName(original),\n },\n handled: true,\n type: 'instrument',\n },\n };\n\n // If Instrument integration has been called before TryCatch, get the name of original function\n if (original.__sentry_original__) {\n wrapOptions.mechanism.data.handler = getFunctionName(original.__sentry_original__);\n }\n\n // Otherwise wrap directly\n return wrap(original, wrapOptions);\n });\n }\n });\n\n return originalSend.apply(this, args);\n };\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/transports/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EACL,KAAK,EACL,OAAO,EACP,QAAQ,IAAI,cAAc,EAC1B,iBAAiB,EAEjB,SAAS,EACT,gBAAgB,EACjB,MAAM,eAAe,CAAC;AACvB,OAAO,EAKL,aAAa,EAEd,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/transports/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EACL,KAAK,EACL,OAAO,EACP,QAAQ,IAAI,cAAc,EAC1B,iBAAiB,EAEjB,SAAS,EACT,gBAAgB,EACjB,MAAM,eAAe,CAAC;AACvB,OAAO,EAKL,aAAa,EAEd,MAAM,eAAe,CAAC;AAevB,0CAA0C;AAC1C,8BAAsB,aAAc,YAAW,SAAS;IAiB5B,OAAO,EAAE,gBAAgB;IAhBnD;;OAEG;IACI,GAAG,EAAE,MAAM,CAAC;IAEnB,0CAA0C;IAC1C,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC;IAE7B,4CAA4C;IAC5C,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC,cAAc,CAAC,CAAyB;IAElF,gEAAgE;IAChE,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAM;IAE1D,SAAS,CAAC,SAAS,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAM;gBAE1B,OAAO,EAAE,gBAAgB;IAcnD;;OAEG;IACI,SAAS,CAAC,CAAC,EAAE,KAAK,GAAG,WAAW,CAAC,cAAc,CAAC;IAIvD;;OAEG;IACI,KAAK,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC,OAAO,CAAC;IAIpD;;OAEG;IACI,eAAe,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,iBAAiB,GAAG,IAAI;IAc1E;;OAEG;IACH,SAAS,CAAC,cAAc,IAAI,IAAI;IA0ChC;;OAEG;IACH,SAAS,CAAC,eAAe,CAAC,EACxB,WAAW,EACX,QAAQ,EACR,OAAO,EACP,OAAO,EACP,MAAM,GACP,EAAE;QACD,WAAW,EAAE,iBAAiB,CAAC;QAC/B,QAAQ,EAAE,QAAQ,GAAG,cAAc,CAAC;QACpC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC;QACvC,OAAO,EAAE,CAAC,KAAK,CAAC,EAAE,cAAc,GAAG,WAAW,CAAC,cAAc,CAAC,GAAG,IAAI,GAAG,SAAS,KAAK,IAAI,CAAC;QAC3F,MAAM,EAAE,CAAC,MAAM,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;KACpC,GAAG,IAAI;IAkBR;;OAEG;IACH,SAAS,CAAC,cAAc,CAAC,WAAW,EAAE,iBAAiB,GAAG,IAAI;IAK9D;;OAEG;IACH,SAAS,CAAC,cAAc,CAAC,WAAW,EAAE,iBAAiB,GAAG,OAAO;IAIjE;;OAEG;IACH,SAAS,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,GAAG,OAAO;CA+B5E"}
|
package/esm/transports/base.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { __read, __values } from "tslib";
|
|
1
|
+
import { __assign, __read, __values } from "tslib";
|
|
2
2
|
import { API } from '@sentry/core';
|
|
3
3
|
import { Status, } from '@sentry/types';
|
|
4
4
|
import { dateTimestampInSeconds, getGlobalObject, logger, parseRetryAfterHeader, PromiseBuffer, SentryError, } from '@sentry/utils';
|
|
5
|
+
import { sendReport } from './utils';
|
|
5
6
|
var CATEGORY_MAPPING = {
|
|
6
7
|
event: 'error',
|
|
7
8
|
transaction: 'transaction',
|
|
@@ -66,10 +67,6 @@ var BaseTransport = /** @class */ (function () {
|
|
|
66
67
|
if (!this.options.sendClientReports) {
|
|
67
68
|
return;
|
|
68
69
|
}
|
|
69
|
-
if (!global.navigator || typeof global.navigator.sendBeacon !== 'function') {
|
|
70
|
-
logger.warn('Beacon API not available, skipping sending outcomes.');
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
70
|
var outcomes = this._outcomes;
|
|
74
71
|
this._outcomes = {};
|
|
75
72
|
// Nothing to send
|
|
@@ -80,7 +77,7 @@ var BaseTransport = /** @class */ (function () {
|
|
|
80
77
|
logger.log("Flushing outcomes:\n" + JSON.stringify(outcomes, null, 2));
|
|
81
78
|
var url = this._api.getEnvelopeEndpointWithUrlEncodedAuth();
|
|
82
79
|
// Envelope header is required to be at least an empty object
|
|
83
|
-
var envelopeHeader = JSON.stringify({});
|
|
80
|
+
var envelopeHeader = JSON.stringify(__assign({}, (this.options.tunnel && { dsn: this._api.getDsn().toString() })));
|
|
84
81
|
var itemHeaders = JSON.stringify({
|
|
85
82
|
type: 'client_report',
|
|
86
83
|
});
|
|
@@ -96,7 +93,12 @@ var BaseTransport = /** @class */ (function () {
|
|
|
96
93
|
}),
|
|
97
94
|
});
|
|
98
95
|
var envelope = envelopeHeader + "\n" + itemHeaders + "\n" + item;
|
|
99
|
-
|
|
96
|
+
try {
|
|
97
|
+
sendReport(url, envelope);
|
|
98
|
+
}
|
|
99
|
+
catch (e) {
|
|
100
|
+
logger.error(e);
|
|
101
|
+
}
|
|
100
102
|
};
|
|
101
103
|
/**
|
|
102
104
|
* Handle Sentry repsonse for promise-based transports.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"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K,GAAG,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,gBAAgB;;wBAC/E,KAAuB,IAAA,oBAAA,SAAA,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA,CAAA,gBAAA,4BAAE;4BAA5C,IAAM,QAAQ,WAAA;4BACjB,IAAI,CAAC,WAAW,CAAC,QAAQ,IAAI,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,CAAC;yBAC7D;;;;;;;;;iBACF;;;;;;;;;YACD,OAAO,IAAI,CAAC;SACb;aAAM,IAAI,QAAQ,EAAE;YACnB,IAAI,CAAC,WAAW,CAAC,GAAG,GAAG,IAAI,IAAI,CAAC,GAAG,GAAG,qBAAqB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC;YAC5E,OAAO,IAAI,CAAC;SACb;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IACH,oBAAC;AAAD,CAAC,AA9LD,IA8LC","sourcesContent":["import { API } from '@sentry/core';\nimport {\n Event,\n Outcome,\n Response as SentryResponse,\n SentryRequestType,\n Status,\n Transport,\n TransportOptions,\n} from '@sentry/types';\nimport {\n dateTimestampInSeconds,\n getGlobalObject,\n logger,\n parseRetryAfterHeader,\n PromiseBuffer,\n SentryError,\n} from '@sentry/utils';\n\nconst CATEGORY_MAPPING: {\n [key in SentryRequestType]: string;\n} = {\n event: 'error',\n transaction: 'transaction',\n session: 'session',\n attachment: 'attachment',\n};\n\nconst global = getGlobalObject<Window>();\n\n/** Base Transport class implementation */\nexport abstract class BaseTransport implements Transport {\n /**\n * @deprecated\n */\n public url: string;\n\n /** Helper to get Sentry API endpoints. */\n protected readonly _api: API;\n\n /** A simple buffer holding all requests. */\n protected readonly _buffer: PromiseBuffer<SentryResponse> = new PromiseBuffer(30);\n\n /** Locks transport after receiving rate limits in a response */\n protected readonly _rateLimits: Record<string, Date> = {};\n\n protected _outcomes: { [key: string]: number } = {};\n\n public constructor(public options: TransportOptions) {\n this._api = new API(options.dsn, options._metadata, options.tunnel);\n // eslint-disable-next-line deprecation/deprecation\n this.url = this._api.getStoreEndpointWithUrlEncodedAuth();\n\n if (this.options.sendClientReports && global.document) {\n global.document.addEventListener('visibilitychange', () => {\n if (global.document.visibilityState === 'hidden') {\n this._flushOutcomes();\n }\n });\n }\n }\n\n /**\n * @inheritDoc\n */\n public sendEvent(_: Event): PromiseLike<SentryResponse> {\n throw new SentryError('Transport Class has to implement `sendEvent` method');\n }\n\n /**\n * @inheritDoc\n */\n public close(timeout?: number): PromiseLike<boolean> {\n return this._buffer.drain(timeout);\n }\n\n /**\n * @inheritDoc\n */\n public recordLostEvent(reason: Outcome, category: SentryRequestType): void {\n if (!this.options.sendClientReports) {\n return;\n }\n // We want to track each category (event, transaction, session) separately\n // but still keep the distinction between different type of outcomes.\n // We could use nested maps, but it's much easier to read and type this way.\n // A correct type for map-based implementation if we want to go that route\n // would be `Partial<Record<SentryRequestType, Partial<Record<Outcome, number>>>>`\n const key = `${CATEGORY_MAPPING[category]}:${reason}`;\n logger.log(`Adding outcome: ${key}`);\n this._outcomes[key] = (this._outcomes[key] ?? 0) + 1;\n }\n\n /**\n * Send outcomes as an envelope\n */\n protected _flushOutcomes(): void {\n if (!this.options.sendClientReports) {\n return;\n }\n\n if (!global.navigator || typeof global.navigator.sendBeacon !== 'function') {\n logger.warn('Beacon API not available, skipping sending outcomes.');\n return;\n }\n\n const outcomes = this._outcomes;\n this._outcomes = {};\n\n // Nothing to send\n if (!Object.keys(outcomes).length) {\n logger.log('No outcomes to flush');\n return;\n }\n\n logger.log(`Flushing outcomes:\\n${JSON.stringify(outcomes, null, 2)}`);\n\n const url = this._api.getEnvelopeEndpointWithUrlEncodedAuth();\n // Envelope header is required to be at least an empty object\n const envelopeHeader = JSON.stringify({});\n const itemHeaders = JSON.stringify({\n type: 'client_report',\n });\n const item = JSON.stringify({\n timestamp: dateTimestampInSeconds(),\n discarded_events: Object.keys(outcomes).map(key => {\n const [category, reason] = key.split(':');\n return {\n reason,\n category,\n quantity: outcomes[key],\n };\n }),\n });\n const envelope = `${envelopeHeader}\\n${itemHeaders}\\n${item}`;\n\n global.navigator.sendBeacon(url, envelope);\n }\n\n /**\n * Handle Sentry repsonse for promise-based transports.\n */\n protected _handleResponse({\n requestType,\n response,\n headers,\n resolve,\n reject,\n }: {\n requestType: SentryRequestType;\n response: Response | XMLHttpRequest;\n headers: Record<string, string | null>;\n resolve: (value?: SentryResponse | PromiseLike<SentryResponse> | null | undefined) => void;\n reject: (reason?: unknown) => void;\n }): void {\n const status = Status.fromHttpCode(response.status);\n /**\n * \"The name is case-insensitive.\"\n * https://developer.mozilla.org/en-US/docs/Web/API/Headers/get\n */\n const limited = this._handleRateLimit(headers);\n if (limited)\n logger.warn(`Too many ${requestType} requests, backing off until: ${this._disabledUntil(requestType)}`);\n\n if (status === Status.Success) {\n resolve({ status });\n return;\n }\n\n reject(response);\n }\n\n /**\n * Gets the time that given category is disabled until for rate limiting\n */\n protected _disabledUntil(requestType: SentryRequestType): Date {\n const category = CATEGORY_MAPPING[requestType];\n return this._rateLimits[category] || this._rateLimits.all;\n }\n\n /**\n * Checks if a category is rate limited\n */\n protected _isRateLimited(requestType: SentryRequestType): boolean {\n return this._disabledUntil(requestType) > new Date(Date.now());\n }\n\n /**\n * Sets internal _rateLimits from incoming headers. Returns true if headers contains a non-empty rate limiting header.\n */\n protected _handleRateLimit(headers: Record<string, string | null>): boolean {\n const now = Date.now();\n const rlHeader = headers['x-sentry-rate-limits'];\n const raHeader = headers['retry-after'];\n\n if (rlHeader) {\n // rate limit headers are of the form\n // <header>,<header>,..\n // where each <header> is of the form\n // <retry_after>: <categories>: <scope>: <reason_code>\n // where\n // <retry_after> is a delay in ms\n // <categories> is the event type(s) (error, transaction, etc) being rate limited and is of the form\n // <category>;<category>;...\n // <scope> is what's being limited (org, project, or key) - ignored by SDK\n // <reason_code> is an arbitrary string like \"org_quota\" - ignored by SDK\n for (const limit of rlHeader.trim().split(',')) {\n const parameters = limit.split(':', 2);\n const headerDelay = parseInt(parameters[0], 10);\n const delay = (!isNaN(headerDelay) ? headerDelay : 60) * 1000; // 60sec default\n for (const category of parameters[1].split(';')) {\n this._rateLimits[category || 'all'] = new Date(now + delay);\n }\n }\n return true;\n } else if (raHeader) {\n this._rateLimits.all = new Date(now + parseRetryAfterHeader(now, raHeader));\n return true;\n }\n return false;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/transports/base.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAKL,MAAM,GAGP,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,MAAM,EACN,qBAAqB,EACrB,aAAa,EACb,WAAW,GACZ,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,IAAM,gBAAgB,GAElB;IACF,KAAK,EAAE,OAAO;IACd,WAAW,EAAE,aAAa;IAC1B,OAAO,EAAE,SAAS;IAClB,UAAU,EAAE,YAAY;CACzB,CAAC;AAEF,IAAM,MAAM,GAAG,eAAe,EAAU,CAAC;AAEzC,0CAA0C;AAC1C;IAiBE,uBAA0B,OAAyB;QAAnD,iBAYC;QAZyB,YAAO,GAAP,OAAO,CAAkB;QARnD,4CAA4C;QACzB,YAAO,GAAkC,IAAI,aAAa,CAAC,EAAE,CAAC,CAAC;QAElF,gEAAgE;QAC7C,gBAAW,GAAyB,EAAE,CAAC;QAEhD,cAAS,GAA8B,EAAE,CAAC;QAGlD,IAAI,CAAC,IAAI,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;QACpE,mDAAmD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CAAqC;gBACrC,0DAA0D;gBAC1D,QAAQ;gBACR,qCAAqC;gBACrC,wGAAwG;gBACxG,oCAAoC;gBACpC,8EAA8E;gBAC9E,6EAA6E;gBAC7E,KAAoB,IAAA,KAAA,SAAA,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA,gBAAA,4BAAE;oBAA3C,IAAM,KAAK,WAAA;oBACd,IAAM,UAAU,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;oBACvC,IAAM,WAAW,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;oBAChD,IAAM,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,gBAAgB;;wBAC/E,KAAuB,IAAA,oBAAA,SAAA,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA,CAAA,gBAAA,4BAAE;4BAA5C,IAAM,QAAQ,WAAA;4BACjB,IAAI,CAAC,WAAW,CAAC,QAAQ,IAAI,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,CAAC;yBAC7D;;;;;;;;;iBACF;;;;;;;;;YACD,OAAO,IAAI,CAAC;SACb;aAAM,IAAI,QAAQ,EAAE;YACnB,IAAI,CAAC,WAAW,CAAC,GAAG,GAAG,IAAI,IAAI,CAAC,GAAG,GAAG,qBAAqB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC;YAC5E,OAAO,IAAI,CAAC;SACb;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IACH,oBAAC;AAAD,CAAC,AA7LD,IA6LC","sourcesContent":["import { API } from '@sentry/core';\nimport {\n Event,\n Outcome,\n Response as SentryResponse,\n SentryRequestType,\n Status,\n Transport,\n TransportOptions,\n} from '@sentry/types';\nimport {\n dateTimestampInSeconds,\n getGlobalObject,\n logger,\n parseRetryAfterHeader,\n PromiseBuffer,\n SentryError,\n} from '@sentry/utils';\n\nimport { sendReport } from './utils';\n\nconst CATEGORY_MAPPING: {\n [key in SentryRequestType]: string;\n} = {\n event: 'error',\n transaction: 'transaction',\n session: 'session',\n attachment: 'attachment',\n};\n\nconst global = getGlobalObject<Window>();\n\n/** Base Transport class implementation */\nexport abstract class BaseTransport implements Transport {\n /**\n * @deprecated\n */\n public url: string;\n\n /** Helper to get Sentry API endpoints. */\n protected readonly _api: API;\n\n /** A simple buffer holding all requests. */\n protected readonly _buffer: PromiseBuffer<SentryResponse> = new PromiseBuffer(30);\n\n /** Locks transport after receiving rate limits in a response */\n protected readonly _rateLimits: Record<string, Date> = {};\n\n protected _outcomes: { [key: string]: number } = {};\n\n public constructor(public options: TransportOptions) {\n this._api = new API(options.dsn, options._metadata, options.tunnel);\n // eslint-disable-next-line deprecation/deprecation\n this.url = this._api.getStoreEndpointWithUrlEncodedAuth();\n\n if (this.options.sendClientReports && global.document) {\n global.document.addEventListener('visibilitychange', () => {\n if (global.document.visibilityState === 'hidden') {\n this._flushOutcomes();\n }\n });\n }\n }\n\n /**\n * @inheritDoc\n */\n public sendEvent(_: Event): PromiseLike<SentryResponse> {\n throw new SentryError('Transport Class has to implement `sendEvent` method');\n }\n\n /**\n * @inheritDoc\n */\n public close(timeout?: number): PromiseLike<boolean> {\n return this._buffer.drain(timeout);\n }\n\n /**\n * @inheritDoc\n */\n public recordLostEvent(reason: Outcome, category: SentryRequestType): void {\n if (!this.options.sendClientReports) {\n return;\n }\n // We want to track each category (event, transaction, session) separately\n // but still keep the distinction between different type of outcomes.\n // We could use nested maps, but it's much easier to read and type this way.\n // A correct type for map-based implementation if we want to go that route\n // would be `Partial<Record<SentryRequestType, Partial<Record<Outcome, number>>>>`\n const key = `${CATEGORY_MAPPING[category]}:${reason}`;\n logger.log(`Adding outcome: ${key}`);\n this._outcomes[key] = (this._outcomes[key] ?? 0) + 1;\n }\n\n /**\n * Send outcomes as an envelope\n */\n protected _flushOutcomes(): void {\n if (!this.options.sendClientReports) {\n return;\n }\n\n const outcomes = this._outcomes;\n this._outcomes = {};\n\n // Nothing to send\n if (!Object.keys(outcomes).length) {\n logger.log('No outcomes to flush');\n return;\n }\n\n logger.log(`Flushing outcomes:\\n${JSON.stringify(outcomes, null, 2)}`);\n\n const url = this._api.getEnvelopeEndpointWithUrlEncodedAuth();\n // Envelope header is required to be at least an empty object\n const envelopeHeader = JSON.stringify({ ...(this.options.tunnel && { dsn: this._api.getDsn().toString() }) });\n const itemHeaders = JSON.stringify({\n type: 'client_report',\n });\n const item = JSON.stringify({\n timestamp: dateTimestampInSeconds(),\n discarded_events: Object.keys(outcomes).map(key => {\n const [category, reason] = key.split(':');\n return {\n reason,\n category,\n quantity: outcomes[key],\n };\n }),\n });\n const envelope = `${envelopeHeader}\\n${itemHeaders}\\n${item}`;\n\n try {\n sendReport(url, envelope);\n } catch (e) {\n logger.error(e);\n }\n }\n\n /**\n * Handle Sentry repsonse for promise-based transports.\n */\n protected _handleResponse({\n requestType,\n response,\n headers,\n resolve,\n reject,\n }: {\n requestType: SentryRequestType;\n response: Response | XMLHttpRequest;\n headers: Record<string, string | null>;\n resolve: (value?: SentryResponse | PromiseLike<SentryResponse> | null | undefined) => void;\n reject: (reason?: unknown) => void;\n }): void {\n const status = Status.fromHttpCode(response.status);\n /**\n * \"The name is case-insensitive.\"\n * https://developer.mozilla.org/en-US/docs/Web/API/Headers/get\n */\n const limited = this._handleRateLimit(headers);\n if (limited)\n logger.warn(`Too many ${requestType} requests, backing off until: ${this._disabledUntil(requestType)}`);\n\n if (status === Status.Success) {\n resolve({ status });\n return;\n }\n\n reject(response);\n }\n\n /**\n * Gets the time that given category is disabled until for rate limiting\n */\n protected _disabledUntil(requestType: SentryRequestType): Date {\n const category = CATEGORY_MAPPING[requestType];\n return this._rateLimits[category] || this._rateLimits.all;\n }\n\n /**\n * Checks if a category is rate limited\n */\n protected _isRateLimited(requestType: SentryRequestType): boolean {\n return this._disabledUntil(requestType) > new Date(Date.now());\n }\n\n /**\n * Sets internal _rateLimits from incoming headers. Returns true if headers contains a non-empty rate limiting header.\n */\n protected _handleRateLimit(headers: Record<string, string | null>): boolean {\n const now = Date.now();\n const rlHeader = headers['x-sentry-rate-limits'];\n const raHeader = headers['retry-after'];\n\n if (rlHeader) {\n // rate limit headers are of the form\n // <header>,<header>,..\n // where each <header> is of the form\n // <retry_after>: <categories>: <scope>: <reason_code>\n // where\n // <retry_after> is a delay in ms\n // <categories> is the event type(s) (error, transaction, etc) being rate limited and is of the form\n // <category>;<category>;...\n // <scope> is what's being limited (org, project, or key) - ignored by SDK\n // <reason_code> is an arbitrary string like \"org_quota\" - ignored by SDK\n for (const limit of rlHeader.trim().split(',')) {\n const parameters = limit.split(':', 2);\n const headerDelay = parseInt(parameters[0], 10);\n const delay = (!isNaN(headerDelay) ? headerDelay : 60) * 1000; // 60sec default\n for (const category of parameters[1].split(';')) {\n this._rateLimits[category || 'all'] = new Date(now + delay);\n }\n }\n return true;\n } else if (raHeader) {\n this._rateLimits.all = new Date(now + parseRetryAfterHeader(now, raHeader));\n return true;\n }\n return false;\n }\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Event, Response, Session, TransportOptions } from '@sentry/types';
|
|
2
2
|
import { BaseTransport } from './base';
|
|
3
|
-
|
|
3
|
+
import { FetchImpl } from './utils';
|
|
4
4
|
/** `fetch` based transport */
|
|
5
5
|
export declare class FetchTransport extends BaseTransport {
|
|
6
6
|
/**
|
|
@@ -22,5 +22,4 @@ export declare class FetchTransport extends BaseTransport {
|
|
|
22
22
|
*/
|
|
23
23
|
private _sendRequest;
|
|
24
24
|
}
|
|
25
|
-
export {};
|
|
26
25
|
//# sourceMappingURL=fetch.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/transports/fetch.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAW,QAAQ,EAAiB,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/transports/fetch.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAW,QAAQ,EAAiB,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGnG,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,SAAS,EAAgC,MAAM,SAAS,CAAC;AAElE,8BAA8B;AAC9B,qBAAa,cAAe,SAAQ,aAAa;IAC/C;;OAEG;IACH,OAAO,CAAC,MAAM,CAAe;gBAEV,OAAO,EAAE,gBAAgB,EAAE,SAAS,GAAE,SAA0C;IAKnG;;OAEG;IACI,SAAS,CAAC,KAAK,EAAE,KAAK,GAAG,WAAW,CAAC,QAAQ,CAAC;IAIrD;;OAEG;IACI,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,WAAW,CAAC,QAAQ,CAAC;IAI3D;;;OAGG;IACH,OAAO,CAAC,YAAY;CA6DrB"}
|
package/esm/transports/fetch.js
CHANGED
|
@@ -1,74 +1,9 @@
|
|
|
1
1
|
import { __extends } from "tslib";
|
|
2
2
|
import { eventToSentryRequest, sessionToSentryRequest } from '@sentry/core';
|
|
3
3
|
import { Outcome } from '@sentry/types';
|
|
4
|
-
import {
|
|
4
|
+
import { SentryError, supportsReferrerPolicy, SyncPromise } from '@sentry/utils';
|
|
5
5
|
import { BaseTransport } from './base';
|
|
6
|
-
|
|
7
|
-
* A special usecase for incorrectly wrapped Fetch APIs in conjunction with ad-blockers.
|
|
8
|
-
* Whenever someone wraps the Fetch API and returns the wrong promise chain,
|
|
9
|
-
* this chain becomes orphaned and there is no possible way to capture it's rejections
|
|
10
|
-
* other than allowing it bubble up to this very handler. eg.
|
|
11
|
-
*
|
|
12
|
-
* const f = window.fetch;
|
|
13
|
-
* window.fetch = function () {
|
|
14
|
-
* const p = f.apply(this, arguments);
|
|
15
|
-
*
|
|
16
|
-
* p.then(function() {
|
|
17
|
-
* console.log('hi.');
|
|
18
|
-
* });
|
|
19
|
-
*
|
|
20
|
-
* return p;
|
|
21
|
-
* }
|
|
22
|
-
*
|
|
23
|
-
* `p.then(function () { ... })` is producing a completely separate promise chain,
|
|
24
|
-
* however, what's returned is `p` - the result of original `fetch` call.
|
|
25
|
-
*
|
|
26
|
-
* This mean, that whenever we use the Fetch API to send our own requests, _and_
|
|
27
|
-
* some ad-blocker blocks it, this orphaned chain will _always_ reject,
|
|
28
|
-
* effectively causing another event to be captured.
|
|
29
|
-
* This makes a whole process become an infinite loop, which we need to somehow
|
|
30
|
-
* deal with, and break it in one way or another.
|
|
31
|
-
*
|
|
32
|
-
* To deal with this issue, we are making sure that we _always_ use the real
|
|
33
|
-
* browser Fetch API, instead of relying on what `window.fetch` exposes.
|
|
34
|
-
* The only downside to this would be missing our own requests as breadcrumbs,
|
|
35
|
-
* but because we are already not doing this, it should be just fine.
|
|
36
|
-
*
|
|
37
|
-
* Possible failed fetch error messages per-browser:
|
|
38
|
-
*
|
|
39
|
-
* Chrome: Failed to fetch
|
|
40
|
-
* Edge: Failed to Fetch
|
|
41
|
-
* Firefox: NetworkError when attempting to fetch resource
|
|
42
|
-
* Safari: resource blocked by content blocker
|
|
43
|
-
*/
|
|
44
|
-
function getNativeFetchImplementation() {
|
|
45
|
-
/* eslint-disable @typescript-eslint/unbound-method */
|
|
46
|
-
var _a, _b;
|
|
47
|
-
// Fast path to avoid DOM I/O
|
|
48
|
-
var global = getGlobalObject();
|
|
49
|
-
if (isNativeFetch(global.fetch)) {
|
|
50
|
-
return global.fetch.bind(global);
|
|
51
|
-
}
|
|
52
|
-
var document = global.document;
|
|
53
|
-
var fetchImpl = global.fetch;
|
|
54
|
-
// eslint-disable-next-line deprecation/deprecation
|
|
55
|
-
if (typeof ((_a = document) === null || _a === void 0 ? void 0 : _a.createElement) === "function") {
|
|
56
|
-
try {
|
|
57
|
-
var sandbox = document.createElement('iframe');
|
|
58
|
-
sandbox.hidden = true;
|
|
59
|
-
document.head.appendChild(sandbox);
|
|
60
|
-
if ((_b = sandbox.contentWindow) === null || _b === void 0 ? void 0 : _b.fetch) {
|
|
61
|
-
fetchImpl = sandbox.contentWindow.fetch;
|
|
62
|
-
}
|
|
63
|
-
document.head.removeChild(sandbox);
|
|
64
|
-
}
|
|
65
|
-
catch (e) {
|
|
66
|
-
logger.warn('Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ', e);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return fetchImpl.bind(global);
|
|
70
|
-
/* eslint-enable @typescript-eslint/unbound-method */
|
|
71
|
-
}
|
|
6
|
+
import { getNativeFetchImplementation } from './utils';
|
|
72
7
|
/** `fetch` based transport */
|
|
73
8
|
var FetchTransport = /** @class */ (function (_super) {
|
|
74
9
|
__extends(FetchTransport, _super);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../src/transports/fetch.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAC5E,OAAO,EAAS,OAAO,EAAsD,MAAM,eAAe,CAAC;AACnG,OAAO,
|
|
1
|
+
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../src/transports/fetch.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAC5E,OAAO,EAAS,OAAO,EAAsD,MAAM,eAAe,CAAC;AACnG,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjF,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAa,4BAA4B,EAAE,MAAM,SAAS,CAAC;AAElE,8BAA8B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C;aAChE;YACD,MAAM,MAAM,CAAC;QACf,CAAC,CAAC,CAAC;IACP,CAAC;IACH,qBAAC;AAAD,CAAC,AA1FD,CAAoC,aAAa,GA0FhD","sourcesContent":["import { eventToSentryRequest, sessionToSentryRequest } from '@sentry/core';\nimport { Event, Outcome, Response, SentryRequest, Session, TransportOptions } from '@sentry/types';\nimport { SentryError, supportsReferrerPolicy, SyncPromise } from '@sentry/utils';\n\nimport { BaseTransport } from './base';\nimport { FetchImpl, getNativeFetchImplementation } from './utils';\n\n/** `fetch` based transport */\nexport class FetchTransport extends BaseTransport {\n /**\n * Fetch API reference which always points to native browser implementation.\n */\n private _fetch: typeof fetch;\n\n public constructor(options: TransportOptions, fetchImpl: FetchImpl = getNativeFetchImplementation()) {\n super(options);\n this._fetch = fetchImpl;\n }\n\n /**\n * @inheritDoc\n */\n public sendEvent(event: Event): PromiseLike<Response> {\n return this._sendRequest(eventToSentryRequest(event, this._api), event);\n }\n\n /**\n * @inheritDoc\n */\n public sendSession(session: Session): PromiseLike<Response> {\n return this._sendRequest(sessionToSentryRequest(session, this._api), session);\n }\n\n /**\n * @param sentryRequest Prepared SentryRequest to be delivered\n * @param originalPayload Original payload used to create SentryRequest\n */\n private _sendRequest(sentryRequest: SentryRequest, originalPayload: Event | Session): PromiseLike<Response> {\n if (this._isRateLimited(sentryRequest.type)) {\n this.recordLostEvent(Outcome.RateLimitBackoff, sentryRequest.type);\n\n return Promise.reject({\n event: originalPayload,\n type: sentryRequest.type,\n reason: `Transport for ${sentryRequest.type} requests locked till ${this._disabledUntil(\n sentryRequest.type,\n )} due to too many requests.`,\n status: 429,\n });\n }\n\n const options: RequestInit = {\n body: sentryRequest.body,\n method: 'POST',\n // Despite all stars in the sky saying that Edge supports old draft syntax, aka 'never', 'always', 'origin' and 'default\n // https://caniuse.com/#feat=referrer-policy\n // It doesn't. And it throw exception instead of ignoring this parameter...\n // REF: https://github.com/getsentry/raven-js/issues/1233\n referrerPolicy: (supportsReferrerPolicy() ? 'origin' : '') as ReferrerPolicy,\n };\n if (this.options.fetchParameters !== undefined) {\n Object.assign(options, this.options.fetchParameters);\n }\n if (this.options.headers !== undefined) {\n options.headers = this.options.headers;\n }\n\n return this._buffer\n .add(\n () =>\n new SyncPromise<Response>((resolve, reject) => {\n void this._fetch(sentryRequest.url, options)\n .then(response => {\n const headers = {\n 'x-sentry-rate-limits': response.headers.get('X-Sentry-Rate-Limits'),\n 'retry-after': response.headers.get('Retry-After'),\n };\n this._handleResponse({\n requestType: sentryRequest.type,\n response,\n headers,\n resolve,\n reject,\n });\n })\n .catch(reject);\n }),\n )\n .then(undefined, reason => {\n // It's either buffer rejection or any other xhr/fetch error, which are treated as NetworkError.\n if (reason instanceof SentryError) {\n this.recordLostEvent(Outcome.QueueOverflow, sentryRequest.type);\n } else {\n this.recordLostEvent(Outcome.NetworkError, sentryRequest.type);\n }\n throw reason;\n });\n }\n}\n"]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export declare type FetchImpl = typeof fetch;
|
|
2
|
+
/**
|
|
3
|
+
* A special usecase for incorrectly wrapped Fetch APIs in conjunction with ad-blockers.
|
|
4
|
+
* Whenever someone wraps the Fetch API and returns the wrong promise chain,
|
|
5
|
+
* this chain becomes orphaned and there is no possible way to capture it's rejections
|
|
6
|
+
* other than allowing it bubble up to this very handler. eg.
|
|
7
|
+
*
|
|
8
|
+
* const f = window.fetch;
|
|
9
|
+
* window.fetch = function () {
|
|
10
|
+
* const p = f.apply(this, arguments);
|
|
11
|
+
*
|
|
12
|
+
* p.then(function() {
|
|
13
|
+
* console.log('hi.');
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* return p;
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* `p.then(function () { ... })` is producing a completely separate promise chain,
|
|
20
|
+
* however, what's returned is `p` - the result of original `fetch` call.
|
|
21
|
+
*
|
|
22
|
+
* This mean, that whenever we use the Fetch API to send our own requests, _and_
|
|
23
|
+
* some ad-blocker blocks it, this orphaned chain will _always_ reject,
|
|
24
|
+
* effectively causing another event to be captured.
|
|
25
|
+
* This makes a whole process become an infinite loop, which we need to somehow
|
|
26
|
+
* deal with, and break it in one way or another.
|
|
27
|
+
*
|
|
28
|
+
* To deal with this issue, we are making sure that we _always_ use the real
|
|
29
|
+
* browser Fetch API, instead of relying on what `window.fetch` exposes.
|
|
30
|
+
* The only downside to this would be missing our own requests as breadcrumbs,
|
|
31
|
+
* but because we are already not doing this, it should be just fine.
|
|
32
|
+
*
|
|
33
|
+
* Possible failed fetch error messages per-browser:
|
|
34
|
+
*
|
|
35
|
+
* Chrome: Failed to fetch
|
|
36
|
+
* Edge: Failed to Fetch
|
|
37
|
+
* Firefox: NetworkError when attempting to fetch resource
|
|
38
|
+
* Safari: resource blocked by content blocker
|
|
39
|
+
*/
|
|
40
|
+
export declare function getNativeFetchImplementation(): FetchImpl;
|
|
41
|
+
/**
|
|
42
|
+
* Sends sdk client report using sendBeacon or fetch as a fallback if available
|
|
43
|
+
*
|
|
44
|
+
* @param url report endpoint
|
|
45
|
+
* @param body report payload
|
|
46
|
+
*/
|
|
47
|
+
export declare function sendReport(url: string, body: string): void;
|
|
48
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/transports/utils.ts"],"names":[],"mappings":"AAKA,oBAAY,SAAS,GAAG,OAAO,KAAK,CAAC;AAErC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,4BAA4B,IAAI,SAAS,CA+BxD;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAqB1D"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { forget, getGlobalObject, isNativeFetch, logger, supportsFetch } from '@sentry/utils';
|
|
2
|
+
var global = getGlobalObject();
|
|
3
|
+
var cachedFetchImpl;
|
|
4
|
+
/**
|
|
5
|
+
* A special usecase for incorrectly wrapped Fetch APIs in conjunction with ad-blockers.
|
|
6
|
+
* Whenever someone wraps the Fetch API and returns the wrong promise chain,
|
|
7
|
+
* this chain becomes orphaned and there is no possible way to capture it's rejections
|
|
8
|
+
* other than allowing it bubble up to this very handler. eg.
|
|
9
|
+
*
|
|
10
|
+
* const f = window.fetch;
|
|
11
|
+
* window.fetch = function () {
|
|
12
|
+
* const p = f.apply(this, arguments);
|
|
13
|
+
*
|
|
14
|
+
* p.then(function() {
|
|
15
|
+
* console.log('hi.');
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* return p;
|
|
19
|
+
* }
|
|
20
|
+
*
|
|
21
|
+
* `p.then(function () { ... })` is producing a completely separate promise chain,
|
|
22
|
+
* however, what's returned is `p` - the result of original `fetch` call.
|
|
23
|
+
*
|
|
24
|
+
* This mean, that whenever we use the Fetch API to send our own requests, _and_
|
|
25
|
+
* some ad-blocker blocks it, this orphaned chain will _always_ reject,
|
|
26
|
+
* effectively causing another event to be captured.
|
|
27
|
+
* This makes a whole process become an infinite loop, which we need to somehow
|
|
28
|
+
* deal with, and break it in one way or another.
|
|
29
|
+
*
|
|
30
|
+
* To deal with this issue, we are making sure that we _always_ use the real
|
|
31
|
+
* browser Fetch API, instead of relying on what `window.fetch` exposes.
|
|
32
|
+
* The only downside to this would be missing our own requests as breadcrumbs,
|
|
33
|
+
* but because we are already not doing this, it should be just fine.
|
|
34
|
+
*
|
|
35
|
+
* Possible failed fetch error messages per-browser:
|
|
36
|
+
*
|
|
37
|
+
* Chrome: Failed to fetch
|
|
38
|
+
* Edge: Failed to Fetch
|
|
39
|
+
* Firefox: NetworkError when attempting to fetch resource
|
|
40
|
+
* Safari: resource blocked by content blocker
|
|
41
|
+
*/
|
|
42
|
+
export function getNativeFetchImplementation() {
|
|
43
|
+
var _a, _b;
|
|
44
|
+
if (cachedFetchImpl) {
|
|
45
|
+
return cachedFetchImpl;
|
|
46
|
+
}
|
|
47
|
+
/* eslint-disable @typescript-eslint/unbound-method */
|
|
48
|
+
// Fast path to avoid DOM I/O
|
|
49
|
+
if (isNativeFetch(global.fetch)) {
|
|
50
|
+
return (cachedFetchImpl = global.fetch.bind(global));
|
|
51
|
+
}
|
|
52
|
+
var document = global.document;
|
|
53
|
+
var fetchImpl = global.fetch;
|
|
54
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
55
|
+
if (typeof ((_a = document) === null || _a === void 0 ? void 0 : _a.createElement) === "function") {
|
|
56
|
+
try {
|
|
57
|
+
var sandbox = document.createElement('iframe');
|
|
58
|
+
sandbox.hidden = true;
|
|
59
|
+
document.head.appendChild(sandbox);
|
|
60
|
+
if ((_b = sandbox.contentWindow) === null || _b === void 0 ? void 0 : _b.fetch) {
|
|
61
|
+
fetchImpl = sandbox.contentWindow.fetch;
|
|
62
|
+
}
|
|
63
|
+
document.head.removeChild(sandbox);
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
logger.warn('Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ', e);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return (cachedFetchImpl = fetchImpl.bind(global));
|
|
70
|
+
/* eslint-enable @typescript-eslint/unbound-method */
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Sends sdk client report using sendBeacon or fetch as a fallback if available
|
|
74
|
+
*
|
|
75
|
+
* @param url report endpoint
|
|
76
|
+
* @param body report payload
|
|
77
|
+
*/
|
|
78
|
+
export function sendReport(url, body) {
|
|
79
|
+
var isRealNavigator = Object.prototype.toString.call(global && global.navigator) === '[object Navigator]';
|
|
80
|
+
var hasSendBeacon = isRealNavigator && typeof global.navigator.sendBeacon === 'function';
|
|
81
|
+
if (hasSendBeacon) {
|
|
82
|
+
// Prevent illegal invocations - https://xgwang.me/posts/you-may-not-know-beacon/#it-may-throw-error%2C-be-sure-to-catch
|
|
83
|
+
var sendBeacon = global.navigator.sendBeacon.bind(global.navigator);
|
|
84
|
+
return sendBeacon(url, body);
|
|
85
|
+
}
|
|
86
|
+
if (supportsFetch()) {
|
|
87
|
+
var fetch_1 = getNativeFetchImplementation();
|
|
88
|
+
return forget(fetch_1(url, {
|
|
89
|
+
body: body,
|
|
90
|
+
method: 'POST',
|
|
91
|
+
credentials: 'omit',
|
|
92
|
+
keepalive: true,
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/transports/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9F,IAAM,MAAM,GAAG,eAAe,EAAU,CAAC;AACzC,IAAI,eAA0B,CAAC;AAI/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,UAAU,4BAA4B;;IAC1C,IAAI,eAAe,EAAE;QACnB,OAAO,eAAe,CAAC;KACxB;IAED,sDAAsD;IAEtD,6BAA6B;IAC7B,IAAI,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;QAC/B,OAAO,CAAC,eAAe,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;KACtD;IAED,IAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;IACjC,IAAI,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC;IAC7B,mDAAmD;IACnD,IAAI,cAAO,QAAQ,0CAAE,aAAa,CAAA,KAAK,UAAU,EAAE;QACjD,IAAI;YACF,IAAM,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;YACjD,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;YACtB,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;YACnC,UAAI,OAAO,CAAC,aAAa,0CAAE,KAAK,EAAE;gBAChC,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC;aACzC;YACD,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;SACpC;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,CAAC,IAAI,CAAC,iFAAiF,EAAE,CAAC,CAAC,CAAC;SACnG;KACF;IAED,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAClD,qDAAqD;AACvD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,GAAW,EAAE,IAAY;IAClD,IAAM,eAAe,GAAG,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,oBAAoB,CAAC;IAC5G,IAAM,aAAa,GAAG,eAAe,IAAI,OAAO,MAAM,CAAC,SAAS,CAAC,UAAU,KAAK,UAAU,CAAC;IAE3F,IAAI,aAAa,EAAE;QACjB,wHAAwH;QACxH,IAAM,UAAU,GAAG,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QACtE,OAAO,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;KAC9B;IAED,IAAI,aAAa,EAAE,EAAE;QACnB,IAAM,OAAK,GAAG,4BAA4B,EAAE,CAAC;QAC7C,OAAO,MAAM,CACX,OAAK,CAAC,GAAG,EAAE;YACT,IAAI,MAAA;YACJ,MAAM,EAAE,MAAM;YACd,WAAW,EAAE,MAAM;YACnB,SAAS,EAAE,IAAI;SAChB,CAAC,CACH,CAAC;KACH;AACH,CAAC","sourcesContent":["import { forget, getGlobalObject, isNativeFetch, logger, supportsFetch } from '@sentry/utils';\n\nconst global = getGlobalObject<Window>();\nlet cachedFetchImpl: FetchImpl;\n\nexport type FetchImpl = typeof fetch;\n\n/**\n * A special usecase for incorrectly wrapped Fetch APIs in conjunction with ad-blockers.\n * Whenever someone wraps the Fetch API and returns the wrong promise chain,\n * this chain becomes orphaned and there is no possible way to capture it's rejections\n * other than allowing it bubble up to this very handler. eg.\n *\n * const f = window.fetch;\n * window.fetch = function () {\n * const p = f.apply(this, arguments);\n *\n * p.then(function() {\n * console.log('hi.');\n * });\n *\n * return p;\n * }\n *\n * `p.then(function () { ... })` is producing a completely separate promise chain,\n * however, what's returned is `p` - the result of original `fetch` call.\n *\n * This mean, that whenever we use the Fetch API to send our own requests, _and_\n * some ad-blocker blocks it, this orphaned chain will _always_ reject,\n * effectively causing another event to be captured.\n * This makes a whole process become an infinite loop, which we need to somehow\n * deal with, and break it in one way or another.\n *\n * To deal with this issue, we are making sure that we _always_ use the real\n * browser Fetch API, instead of relying on what `window.fetch` exposes.\n * The only downside to this would be missing our own requests as breadcrumbs,\n * but because we are already not doing this, it should be just fine.\n *\n * Possible failed fetch error messages per-browser:\n *\n * Chrome: Failed to fetch\n * Edge: Failed to Fetch\n * Firefox: NetworkError when attempting to fetch resource\n * Safari: resource blocked by content blocker\n */\nexport function getNativeFetchImplementation(): FetchImpl {\n if (cachedFetchImpl) {\n return cachedFetchImpl;\n }\n\n /* eslint-disable @typescript-eslint/unbound-method */\n\n // Fast path to avoid DOM I/O\n if (isNativeFetch(global.fetch)) {\n return (cachedFetchImpl = global.fetch.bind(global));\n }\n\n const document = global.document;\n let fetchImpl = global.fetch;\n // eslint-disable-next-line deprecation/deprecation\n if (typeof document?.createElement === `function`) {\n try {\n const sandbox = document.createElement('iframe');\n sandbox.hidden = true;\n document.head.appendChild(sandbox);\n if (sandbox.contentWindow?.fetch) {\n fetchImpl = sandbox.contentWindow.fetch;\n }\n document.head.removeChild(sandbox);\n } catch (e) {\n logger.warn('Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ', e);\n }\n }\n\n return (cachedFetchImpl = fetchImpl.bind(global));\n /* eslint-enable @typescript-eslint/unbound-method */\n}\n\n/**\n * Sends sdk client report using sendBeacon or fetch as a fallback if available\n *\n * @param url report endpoint\n * @param body report payload\n */\nexport function sendReport(url: string, body: string): void {\n const isRealNavigator = Object.prototype.toString.call(global && global.navigator) === '[object Navigator]';\n const hasSendBeacon = isRealNavigator && typeof global.navigator.sendBeacon === 'function';\n\n if (hasSendBeacon) {\n // Prevent illegal invocations - https://xgwang.me/posts/you-may-not-know-beacon/#it-may-throw-error%2C-be-sure-to-catch\n const sendBeacon = global.navigator.sendBeacon.bind(global.navigator);\n return sendBeacon(url, body);\n }\n\n if (supportsFetch()) {\n const fetch = getNativeFetchImplementation();\n return forget(\n fetch(url, {\n body,\n method: 'POST',\n credentials: 'omit',\n keepalive: true,\n }),\n );\n }\n}\n"]}
|