UNPKG

@sentry/browser

Version:
31 lines (30 loc) • 1.58 kB
const require_debug_build = require("../debug-build.js"); const require_helpers = require("../helpers.js"); let _sentry_core = require("@sentry/core"); let _sentry_conventions_attributes = require("@sentry/conventions/attributes"); // src/tracing/backgroundtab.ts /** * Add a listener that cancels and finishes a transaction when the global * document is hidden. */ function registerBackgroundTabDetection() { if (require_helpers.WINDOW.document) require_helpers.WINDOW.document.addEventListener("visibilitychange", () => { const activeSpan = (0, _sentry_core.getActiveSpan)(); if (!activeSpan) return; const rootSpan = (0, _sentry_core.getRootSpan)(activeSpan); if (require_helpers.WINDOW.document.hidden && rootSpan) { const cancelledStatus = "cancelled"; const { attributes: { [_sentry_conventions_attributes.SENTRY_OP]: op }, status } = (0, _sentry_core.spanToJSON)(rootSpan); if (require_debug_build.DEBUG_BUILD) _sentry_core.debug.log(`[Tracing] Transaction: ${cancelledStatus} -> since tab moved to the background, op: ${op}`); if (status === "ok") rootSpan.setStatus({ code: _sentry_core.SPAN_STATUS_ERROR, message: cancelledStatus }); rootSpan.setAttribute(_sentry_conventions_attributes.SENTRY_CANCELLATION_REASON, "document.hidden"); rootSpan.end(); } }); else require_debug_build.DEBUG_BUILD && _sentry_core.debug.warn("[Tracing] Could not set up background tab detection due to lack of global document"); } exports.registerBackgroundTabDetection = registerBackgroundTabDetection; //# sourceMappingURL=backgroundtab.js.map