UNPKG

@sentry/browser

Version:
60 lines (59 loc) • 1.93 kB
let _sentry_core = require("@sentry/core"); // src/integrations/reportingobserver.ts const WINDOW = _sentry_core.GLOBAL_OBJ; /** * Tells whether current environment supports ReportingObserver API * {@link supportsReportingObserver}. * * @returns Answer to the given question. */ function supportsReportingObserver() { return "ReportingObserver" in WINDOW; } const INTEGRATION_NAME = "ReportingObserver"; const SETUP_CLIENTS = /* @__PURE__ */ new WeakMap(); const _reportingObserverIntegration = ((options = {}) => { const types = options.types || [ "crash", "deprecation", "intervention" ]; /** Handler for the reporting observer. */ function handler(reports) { if (!SETUP_CLIENTS.has((0, _sentry_core.getClient)())) return; for (const report of reports) (0, _sentry_core.withScope)((scope) => { scope.setExtra("url", report.url); const label = `ReportingObserver [${report.type}]`; let details = "No details available"; if (report.body) { const plainBody = {}; for (const prop in report.body) plainBody[prop] = report.body[prop]; scope.setExtra("body", plainBody); if (report.type === "crash") { const body = report.body; details = [body.crashId || "", body.reason || ""].join(" ").trim() || details; } else details = report.body.message || details; } (0, _sentry_core.captureMessage)(`${label}: ${details}`); }); } return { name: INTEGRATION_NAME, setupOnce() { if (!supportsReportingObserver()) return; new WINDOW.ReportingObserver(handler, { buffered: true, types }).observe(); }, setup(client) { SETUP_CLIENTS.set(client, true); } }; }); /** * Reporting API integration - https://w3c.github.io/reporting/ */ const reportingObserverIntegration = (0, _sentry_core.defineIntegration)(_reportingObserverIntegration); exports.reportingObserverIntegration = reportingObserverIntegration; //# sourceMappingURL=reportingobserver.js.map