Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(browser): Use getGlobalObject for document check #3996

Merged
merged 3 commits into from Sep 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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