Skip to content

Commit 06fa32c

Browse files
committed
starting
1 parent a5bfa80 commit 06fa32c

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

packages/hub/src/hub.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import {
2323
import {
2424
consoleSandbox,
2525
dateTimestampInSeconds,
26-
getGlobalObject,
2726
getGlobalSingleton,
27+
GLOBAL_OBJ,
2828
isNodeEnv,
2929
logger,
3030
uuid4,
@@ -413,8 +413,7 @@ export class Hub implements HubInterface {
413413
const { release, environment } = (client && client.getOptions()) || {};
414414

415415
// Will fetch userAgent if called from browser sdk
416-
const global = getGlobalObject<{ navigator?: { userAgent?: string } }>();
417-
const { userAgent } = global.navigator || {};
416+
const { userAgent } = GLOBAL_OBJ.navigator || {};
418417

419418
const session = makeSession({
420419
release,
@@ -500,12 +499,11 @@ export class Hub implements HubInterface {
500499
* at the call-site. We always access the carrier through this function, so we can guarantee that `__SENTRY__` is there.
501500
**/
502501
export function getMainCarrier(): Carrier {
503-
const carrier = getGlobalObject();
504-
carrier.__SENTRY__ = carrier.__SENTRY__ || {
502+
GLOBAL_OBJ.__SENTRY__ = GLOBAL_OBJ.__SENTRY__ || {
505503
extensions: {},
506504
hub: undefined,
507505
};
508-
return carrier;
506+
return GLOBAL_OBJ;
509507
}
510508

511509
/**

packages/utils/src/global.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@
77

88
import { Integration } from '@sentry/types';
99

10-
/** Internal */
11-
interface SentryGlobal {
10+
/** An object representing properties that can be found on all globals */
11+
interface GlobalObject {
12+
navigator?: Navigator;
13+
}
14+
15+
/** Internal Sentry extensions on global */
16+
interface SentryGlobal extends GlobalObject {
1217
Sentry?: {
1318
Integrations?: Integration[];
1419
};
@@ -24,7 +29,7 @@ interface SentryGlobal {
2429
};
2530
}
2631

27-
// The code below for 'isGlobalObj' and 'GLOBAL' was copied from core-js before modification
32+
// The code below for 'isGlobalObj' and 'GLOBAL_OBJ' was copied from core-js before modification
2833
// https://github.com/zloirock/core-js/blob/1b944df55282cdc99c90db5f49eb0b6eda2cc0a3/packages/core-js/internals/global.js
2934
// core-js has the following licence:
3035
//
@@ -53,7 +58,7 @@ function isGlobalObj(obj: { Math?: Math }): any | undefined {
5358
return obj && obj.Math == Math ? obj : undefined;
5459
}
5560

56-
const GLOBAL =
61+
export const GLOBAL_OBJ: SentryGlobal =
5762
(typeof globalThis == 'object' && isGlobalObj(globalThis)) ||
5863
// eslint-disable-next-line no-restricted-globals
5964
(typeof window == 'object' && isGlobalObj(window)) ||
@@ -70,7 +75,7 @@ const GLOBAL =
7075
* @returns Global scope object
7176
*/
7277
export function getGlobalObject<T>(): T & SentryGlobal {
73-
return GLOBAL as T & SentryGlobal;
78+
return GLOBAL_OBJ as T & SentryGlobal;
7479
}
7580

7681
/**
@@ -85,7 +90,7 @@ export function getGlobalObject<T>(): T & SentryGlobal {
8590
* @returns the singleton
8691
*/
8792
export function getGlobalSingleton<T>(name: keyof SentryGlobal['__SENTRY__'], creator: () => T, obj?: unknown): T {
88-
const global = (obj || GLOBAL) as SentryGlobal;
93+
const global = (obj || GLOBAL_OBJ) as SentryGlobal;
8994
const __SENTRY__ = (global.__SENTRY__ = global.__SENTRY__ || {});
9095
const singleton = __SENTRY__[name] || (__SENTRY__[name] = creator());
9196
return singleton;

0 commit comments

Comments
 (0)