UNPKG

@sentry/integrations

Version:
100 lines (79 loc) 2.53 kB
Object.defineProperty(exports, '__esModule', { value: true }); const utils = require('@sentry/utils'); const WINDOW = utils.GLOBAL_OBJ ; /** Reporting API integration - https://w3c.github.io/reporting/ */ class ReportingObserver { /** * @inheritDoc */ static __initStatic() {this.id = 'ReportingObserver';} /** * @inheritDoc */ __init() {this.name = ReportingObserver.id;} /** * Returns current hub. */ /** * @inheritDoc */ constructor( _options = { types: ['crash', 'deprecation', 'intervention'], }, ) {;this._options = _options;ReportingObserver.prototype.__init.call(this);} /** * @inheritDoc */ setupOnce(_, getCurrentHub) { if (!utils.supportsReportingObserver()) { return; } this._getCurrentHub = getCurrentHub; // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any const observer = new (WINDOW ).ReportingObserver(this.handler.bind(this), { buffered: true, types: this._options.types, }); // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access observer.observe(); } /** * @inheritDoc */ handler(reports) { const hub = this._getCurrentHub && this._getCurrentHub(); if (!hub || !hub.getIntegration(ReportingObserver)) { return; } for (const report of reports) { hub.withScope(scope => { scope.setExtra('url', report.url); const label = `ReportingObserver [${report.type}]`; let details = 'No details available'; if (report.body) { // Object.keys doesn't work on ReportBody, as all properties are inheirted const plainBody = {}; // eslint-disable-next-line guard-for-in for (const prop in report.body) { plainBody[prop] = report.body[prop]; } scope.setExtra('body', plainBody); if (report.type === 'crash') { const body = report.body ; // A fancy way to create a message out of crashId OR reason OR both OR fallback details = [body.crashId || '', body.reason || ''].join(' ').trim() || details; } else { const body = report.body ; details = body.message || details; } } hub.captureMessage(`${label}: ${details}`); }); } } } ReportingObserver.__initStatic(); exports.ReportingObserver = ReportingObserver; //# sourceMappingURL=reportingobserver.js.map