@sentry/browser
Version:
Official Sentry SDK for browsers
60 lines (59 loc) • 1.87 kB
JavaScript
import { GLOBAL_OBJ, captureMessage, defineIntegration, getClient, withScope } from "@sentry/core";
// src/integrations/reportingobserver.ts
const WINDOW = 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(getClient())) return;
for (const report of reports) 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;
}
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 = defineIntegration(_reportingObserverIntegration);
export { reportingObserverIntegration };
//# sourceMappingURL=reportingobserver.js.map