summaryrefslogtreecommitdiff
path: root/shared/logger/node_modules/@sentry-internal/tracing/esm/browser/backgroundtab.js
diff options
context:
space:
mode:
authorrxliuli <rxliuli@gmail.com>2025-11-04 05:03:50 +0800
committerrxliuli <rxliuli@gmail.com>2025-11-04 05:03:50 +0800
commitbce557cc2dc767628bed6aac87301a1be7c5431b (patch)
treeb51a051228d01fe3306cd7626d4a96768aadb944 /shared/logger/node_modules/@sentry-internal/tracing/esm/browser/backgroundtab.js
init commit
Diffstat (limited to 'shared/logger/node_modules/@sentry-internal/tracing/esm/browser/backgroundtab.js')
-rw-r--r--shared/logger/node_modules/@sentry-internal/tracing/esm/browser/backgroundtab.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/shared/logger/node_modules/@sentry-internal/tracing/esm/browser/backgroundtab.js b/shared/logger/node_modules/@sentry-internal/tracing/esm/browser/backgroundtab.js
new file mode 100644
index 0000000..62c1d20
--- /dev/null
+++ b/shared/logger/node_modules/@sentry-internal/tracing/esm/browser/backgroundtab.js
@@ -0,0 +1,36 @@
+import { getActiveTransaction } from '@sentry/core';
+import { logger } from '@sentry/utils';
+import { WINDOW } from './types.js';
+
+/**
+ * Add a listener that cancels and finishes a transaction when the global
+ * document is hidden.
+ */
+function registerBackgroundTabDetection() {
+ if (WINDOW && WINDOW.document) {
+ WINDOW.document.addEventListener('visibilitychange', () => {
+ const activeTransaction = getActiveTransaction() ;
+ if (WINDOW.document.hidden && activeTransaction) {
+ const statusType = 'cancelled';
+
+ (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) &&
+ logger.log(
+ `[Tracing] Transaction: ${statusType} -> since tab moved to the background, op: ${activeTransaction.op}`,
+ );
+ // We should not set status if it is already set, this prevent important statuses like
+ // error or data loss from being overwritten on transaction.
+ if (!activeTransaction.status) {
+ activeTransaction.setStatus(statusType);
+ }
+ activeTransaction.setTag('visibilitychange', 'document.hidden');
+ activeTransaction.finish();
+ }
+ });
+ } else {
+ (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) &&
+ logger.warn('[Tracing] Could not set up background tab detection due to lack of global document');
+ }
+}
+
+export { registerBackgroundTabDetection };
+//# sourceMappingURL=backgroundtab.js.map