@mtdt.temp/browser-core
Version:
Datadog browser core utilities.
33 lines • 987 B
JavaScript
/**
* inspired by https://mathiasbynens.be/notes/globalthis
*/
export function getGlobalObject() {
if (typeof globalThis === 'object') {
return globalThis;
}
Object.defineProperty(Object.prototype, '_md_temp_', {
get() {
return this;
},
configurable: true,
});
// @ts-ignore _md_temp is defined using defineProperty
let globalObject = _md_temp_;
// @ts-ignore _md_temp is defined using defineProperty
delete Object.prototype._md_temp_;
if (typeof globalObject !== 'object') {
// on safari _md_temp_ is available on window but not globally
// fallback on other browser globals check
if (typeof self === 'object') {
globalObject = self;
}
else if (typeof window === 'object') {
globalObject = window;
}
else {
globalObject = {};
}
}
return globalObject;
}
//# sourceMappingURL=getGlobalObject.js.map