diff --git a/src/platform/browser/globalThis.ts b/src/platform/browser/globalThis.ts index 34a8254b..ebea1f48 100644 --- a/src/platform/browser/globalThis.ts +++ b/src/platform/browser/globalThis.ts @@ -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) + * - (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;