Skip to content

Commit ba50656

Browse files
authored
fix(browser): Use getGlobalObject for document check (#3996)
* fix(browser): Use getGlobalObject for document check
1 parent b910f96 commit ba50656

File tree

1 file changed

+13
-4
lines changed
  • packages/browser/src/transports

1 file changed

+13
-4
lines changed

packages/browser/src/transports/base.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ import {
88
Transport,
99
TransportOptions,
1010
} from '@sentry/types';
11-
import { dateTimestampInSeconds, logger, parseRetryAfterHeader, PromiseBuffer, SentryError } from '@sentry/utils';
11+
import {
12+
dateTimestampInSeconds,
13+
getGlobalObject,
14+
logger,
15+
parseRetryAfterHeader,
16+
PromiseBuffer,
17+
SentryError,
18+
} from '@sentry/utils';
1219

1320
const CATEGORY_MAPPING: {
1421
[key in SentryRequestType]: string;
@@ -19,6 +26,8 @@ const CATEGORY_MAPPING: {
1926
attachment: 'attachment',
2027
};
2128

29+
const global = getGlobalObject<Window>();
30+
2231
/** Base Transport class implementation */
2332
export abstract class BaseTransport implements Transport {
2433
/**
@@ -42,9 +51,9 @@ export abstract class BaseTransport implements Transport {
4251
// eslint-disable-next-line deprecation/deprecation
4352
this.url = this._api.getStoreEndpointWithUrlEncodedAuth();
4453

45-
if (this.options.sendClientReports && document) {
46-
document.addEventListener('visibilitychange', () => {
47-
if (document.visibilityState === 'hidden') {
54+
if (this.options.sendClientReports && global && global.document) {
55+
global.document.addEventListener('visibilitychange', () => {
56+
if (global.document.visibilityState === 'hidden') {
4857
this._flushOutcomes();
4958
}
5059
});

0 commit comments

Comments
 (0)