Skip to content

Commit

Permalink
fix(browser): Use getGlobalObject for document check (#3996)
Browse files Browse the repository at this point in the history
* fix(browser): Use getGlobalObject for document check
  • Loading branch information
AbhiPrasad committed Sep 21, 2021
1 parent b910f96 commit ba50656
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions packages/browser/src/transports/base.ts
Expand Up @@ -8,7 +8,14 @@ import {
Transport,
TransportOptions,
} from '@sentry/types';
import { dateTimestampInSeconds, logger, parseRetryAfterHeader, PromiseBuffer, SentryError } from '@sentry/utils';
import {
dateTimestampInSeconds,
getGlobalObject,
logger,
parseRetryAfterHeader,
PromiseBuffer,
SentryError,
} from '@sentry/utils';

const CATEGORY_MAPPING: {
[key in SentryRequestType]: string;
Expand All @@ -19,6 +26,8 @@ const CATEGORY_MAPPING: {
attachment: 'attachment',
};

const global = getGlobalObject<Window>();

/** Base Transport class implementation */
export abstract class BaseTransport implements Transport {
/**
Expand All @@ -42,9 +51,9 @@ export abstract class BaseTransport implements Transport {
// eslint-disable-next-line deprecation/deprecation
this.url = this._api.getStoreEndpointWithUrlEncodedAuth();

if (this.options.sendClientReports && document) {
document.addEventListener('visibilitychange', () => {
if (document.visibilityState === 'hidden') {
if (this.options.sendClientReports && global && global.document) {
global.document.addEventListener('visibilitychange', () => {
if (global.document.visibilityState === 'hidden') {
this._flushOutcomes();
}
});
Expand Down

0 comments on commit ba50656

Please sign in to comment.