package.build.npm.esm.transports.fetch.js.map Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of browser Show documentation
Show all versions of browser Show documentation
Official Sentry SDK for browsers
{"version":3,"file":"fetch.js","sources":["../../../../src/transports/fetch.ts"],"sourcesContent":["import { clearCachedImplementation, getNativeImplementation } from '@sentry-internal/browser-utils';\nimport { createTransport } from '@sentry/core';\nimport type { Transport, TransportMakeRequestResponse, TransportRequest } from '@sentry/types';\nimport { rejectedSyncPromise } from '@sentry/utils';\nimport type { WINDOW } from '../helpers';\n\nimport type { BrowserTransportOptions } from './types';\n\n/**\n * Creates a Transport that uses the Fetch API to send events to Sentry.\n */\nexport function makeFetchTransport(\n options: BrowserTransportOptions,\n nativeFetch: typeof WINDOW.fetch | undefined = getNativeImplementation('fetch'),\n): Transport {\n let pendingBodySize = 0;\n let pendingCount = 0;\n\n function makeRequest(request: TransportRequest): PromiseLike {\n const requestSize = request.body.length;\n pendingBodySize += requestSize;\n pendingCount++;\n\n const requestOptions: RequestInit = {\n body: request.body,\n method: 'POST',\n referrerPolicy: 'origin',\n headers: options.headers,\n // Outgoing requests are usually cancelled when navigating to a different page, causing a \"TypeError: Failed to\n // fetch\" error and sending a \"network_error\" client-outcome - in Chrome, the request status shows \"(cancelled)\".\n // The `keepalive` flag keeps outgoing requests alive, even when switching pages. We want this since we're\n // frequently sending events right before the user is switching pages (eg. whenfinishing navigation transactions).\n // Gotchas:\n // - `keepalive` isn't supported by Firefox\n // - As per spec (https://fetch.spec.whatwg.org/#http-network-or-cache-fetch):\n // If the sum of contentLength and inflightKeepaliveBytes is greater than 64 kibibytes, then return a network error.\n // We will therefore only activate the flag when we're below that limit.\n // There is also a limit of requests that can be open at the same time, so we also limit this to 15\n // See https://github.com/getsentry/sentry-javascript/pull/7553 for details\n keepalive: pendingBodySize <= 60_000 && pendingCount < 15,\n ...options.fetchOptions,\n };\n\n if (!nativeFetch) {\n clearCachedImplementation('fetch');\n return rejectedSyncPromise('No fetch implementation available');\n }\n\n try {\n // TODO: This may need a `suppresTracing` call in the future when we switch the browser SDK to OTEL\n return nativeFetch(options.url, requestOptions).then(response => {\n pendingBodySize -= requestSize;\n pendingCount--;\n return {\n statusCode: response.status,\n headers: {\n 'x-sentry-rate-limits': response.headers.get('X-Sentry-Rate-Limits'),\n 'retry-after': response.headers.get('Retry-After'),\n },\n };\n });\n } catch (e) {\n clearCachedImplementation('fetch');\n pendingBodySize -= requestSize;\n pendingCount--;\n return rejectedSyncPromise(e);\n }\n }\n\n return createTransport(options, makeRequest);\n}\n"],"names":[],"mappings":";;;;AAQA;AACA;AACA;AACO,SAAS,kBAAkB;AAClC,EAAE,OAAO;AACT,EAAE,WAAW,GAAoC,uBAAuB,CAAC,OAAO,CAAC;AACjF,EAAa;AACb,EAAE,IAAI,eAAgB,GAAE,CAAC,CAAA;AACzB,EAAE,IAAI,YAAa,GAAE,CAAC,CAAA;AACtB;AACA,EAAE,SAAS,WAAW,CAAC,OAAO,EAA+D;AAC7F,IAAI,MAAM,WAAY,GAAE,OAAO,CAAC,IAAI,CAAC,MAAM,CAAA;AAC3C,IAAI,eAAA,IAAmB,WAAW,CAAA;AAClC,IAAI,YAAY,EAAE,CAAA;AAClB;AACA,IAAI,MAAM,cAAc,GAAgB;AACxC,MAAM,IAAI,EAAE,OAAO,CAAC,IAAI;AACxB,MAAM,MAAM,EAAE,MAAM;AACpB,MAAM,cAAc,EAAE,QAAQ;AAC9B,MAAM,OAAO,EAAE,OAAO,CAAC,OAAO;AAC9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,SAAS,EAAE,eAAgB,IAAG,SAAU,YAAA,GAAe,EAAE;AAC/D,MAAM,GAAG,OAAO,CAAC,YAAY;AAC7B,KAAK,CAAA;AACL;AACA,IAAI,IAAI,CAAC,WAAW,EAAE;AACtB,MAAM,yBAAyB,CAAC,OAAO,CAAC,CAAA;AACxC,MAAM,OAAO,mBAAmB,CAAC,mCAAmC,CAAC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