Skip to content
This repository has been archived by the owner on Nov 10, 2022. It is now read-only.

Commit

Permalink
fix: align globalThis fallbacks with otel-core
Browse files Browse the repository at this point in the history
  • Loading branch information
legendecas committed Oct 22, 2021
1 parent a752e7f commit 424e62a
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/platform/browser/globalThis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@
* limitations under the License.
*/

// Updates to this file should also be replicated to @opentelemetry/api-metrics and
// @opentelemetry/core too.

/**
* - globalThis (New standard)
* - self (Will return the current window instance for supported browsers)
* - window (fallback for older browser implementations)
* - global (NodeJS implementation)
* - <object> (When all else fails)
*/

/** only globals that common to node and browsers are allowed */
// eslint-disable-next-line node/no-unsupported-features/es-builtins, no-undef
export const _globalThis = typeof globalThis === 'object' ? globalThis : window;
export const _globalThis: typeof globalThis =
typeof globalThis === 'object' ? globalThis :
typeof self === 'object' ? self :
typeof window === 'object' ? window :
typeof global === 'object' ? global :
{} as typeof globalThis;

0 comments on commit 424e62a

Please sign in to comment.