This commit is contained in:
MarSeventh
2024-07-19 23:26:06 +08:00
commit 4e0c55d1f9
1401 changed files with 69819 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
import { getActiveTransaction, spanToJSON } from '@sentry/core';
import { logger } from '@sentry/utils';
import { DEBUG_BUILD } from '../common/debug-build.js';
import { WINDOW } from './types.js';
/**
* Add a listener that cancels and finishes a transaction when the global
* document is hidden.
*/
function registerBackgroundTabDetection() {
if (WINDOW.document) {
WINDOW.document.addEventListener('visibilitychange', () => {
// eslint-disable-next-line deprecation/deprecation
const activeTransaction = getActiveTransaction() ;
if (WINDOW.document.hidden && activeTransaction) {
const statusType = 'cancelled';
const { op, status } = spanToJSON(activeTransaction);
DEBUG_BUILD &&
logger.log(`[Tracing] Transaction: ${statusType} -> since tab moved to the background, op: ${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 (!status) {
activeTransaction.setStatus(statusType);
}
// TODO: Can we rewrite this to an attribute?
// eslint-disable-next-line deprecation/deprecation
activeTransaction.setTag('visibilitychange', 'document.hidden');
activeTransaction.end();
}
});
} else {
DEBUG_BUILD && logger.warn('[Tracing] Could not set up background tab detection due to lack of global document');
}
}
export { registerBackgroundTabDetection };
//# sourceMappingURL=backgroundtab.js.map