package.build.npm.esm.integrations.reportingobserver.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":"reportingobserver.js","sources":["../../../../src/integrations/reportingobserver.ts"],"sourcesContent":["import { captureMessage, defineIntegration, getClient, withScope } from '@sentry/core';\nimport type { Client, IntegrationFn } from '@sentry/types';\nimport { GLOBAL_OBJ, supportsReportingObserver } from '@sentry/utils';\n\nconst WINDOW = GLOBAL_OBJ as typeof GLOBAL_OBJ & Window;\n\nconst INTEGRATION_NAME = 'ReportingObserver';\n\ninterface Report {\n [key: string]: unknown;\n type: ReportTypes;\n url: string;\n body?: ReportBody;\n}\n\ntype ReportTypes = 'crash' | 'deprecation' | 'intervention';\n\ntype ReportBody = CrashReportBody | DeprecationReportBody | InterventionReportBody;\n\ninterface CrashReportBody {\n [key: string]: unknown;\n crashId: string;\n reason?: string;\n}\n\ninterface DeprecationReportBody {\n [key: string]: unknown;\n id: string;\n anticipatedRemoval?: Date;\n message: string;\n sourceFile?: string;\n lineNumber?: number;\n columnNumber?: number;\n}\n\ninterface InterventionReportBody {\n [key: string]: unknown;\n id: string;\n message: string;\n sourceFile?: string;\n lineNumber?: number;\n columnNumber?: number;\n}\n\ninterface ReportingObserverOptions {\n types?: ReportTypes[];\n}\n\nconst SETUP_CLIENTS = new WeakMap();\n\nconst _reportingObserverIntegration = ((options: ReportingObserverOptions = {}) => {\n const types = options.types || ['crash', 'deprecation', 'intervention'];\n\n /** Handler for the reporting observer. */\n function handler(reports: Report[]): void {\n if (!SETUP_CLIENTS.has(getClient() as Client)) {\n return;\n }\n\n for (const report of reports) {\n withScope(scope => {\n scope.setExtra('url', report.url);\n\n const label = `ReportingObserver [${report.type}]`;\n let details = 'No details available';\n\n if (report.body) {\n // Object.keys doesn't work on ReportBody, as all properties are inheirted\n const plainBody: {\n [key: string]: unknown;\n } = {};\n\n // eslint-disable-next-line guard-for-in\n for (const prop in report.body) {\n plainBody[prop] = report.body[prop];\n }\n\n scope.setExtra('body', plainBody);\n\n if (report.type === 'crash') {\n const body = report.body as CrashReportBody;\n // A fancy way to create a message out of crashId OR reason OR both OR fallback\n details = [body.crashId || '', body.reason || ''].join(' ').trim() || details;\n } else {\n const body = report.body as DeprecationReportBody | InterventionReportBody;\n details = body.message || details;\n }\n }\n\n captureMessage(`${label}: ${details}`);\n });\n }\n }\n\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n if (!supportsReportingObserver()) {\n return;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any\n const observer = new (WINDOW as any).ReportingObserver(handler, {\n buffered: true,\n types,\n });\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n observer.observe();\n },\n\n setup(client): void {\n SETUP_CLIENTS.set(client, true);\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Reporting API integration - https://w3c.github.io/reporting/\n */\nexport const reportingObserverIntegration = defineIntegration(_reportingObserverIntegration);\n"],"names":[],"mappings":";;;AAIA,MAAM,MAAA,GAAS,UAAW,EAAA;AAC1B;AACA,MAAM,gBAAA,GAAmB,mBAAmB,CAAA;;AA0C5C,MAAM,aAAc,GAAE,IAAI,OAAO,EAAmB,CAAA;AACpD;AACA,MAAM,6BAAA,IAAiC,CAAC,OAAO,GAA6B,EAAE,KAAK;AACnF,EAAE,MAAM,KAAA,GAAQ,OAAO,CAAC,KAAA,IAAS,CAAC,OAAO,EAAE,aAAa,EAAE,cAAc,CAAC,CAAA;AACzE;AACA;AACA,EAAE,SAAS,OAAO,CAAC,OAAO,EAAkB;AAC5C,IAAI,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,SAAS,EAAG,EAAU,EAAE;AACnD,MAAM,OAAM;AACZ,KAAI;AACJ;AACA,IAAI,KAAK,MAAM,MAAO,IAAG,OAAO,EAAE;AAClC,MAAM,SAAS,CAAC,KAAA,IAAS;AACzB,QAAQ,KAAK,C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