Skip to content

Commit

Permalink
fix: align globalThis fallbacks with otel-core (open-telemetry#126)
Browse files Browse the repository at this point in the history
Co-authored-by: Valentin Marchaud <contact@vmarchaud.fr>
  • Loading branch information
legendecas and vmarchaud authored Nov 8, 2021
1 parent 65df36c commit 9338171
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion api/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 9338171

Please sign in to comment.