diff --git a/fetch.js b/fetch.js index 5050a247..8f9f27e4 100644 --- a/fetch.js +++ b/fetch.js @@ -597,9 +597,19 @@ export function fetch(input, init) { fetch.polyfill = true -if (!global.fetch) { - global.fetch = fetch - global.Headers = Headers - global.Request = Request - global.Response = Response +var getGlobal = function () { + if (typeof globalThis !== 'undefined') { return globalThis } + if (typeof self !== 'undefined') { return self } + if (typeof window !== 'undefined') { return window } + if (typeof global !== 'undefined') { return global } + throw new Error('unable to locate global object') +} + +var globals = getGlobal() + +if (!globals.fetch) { + globals.fetch = fetch + globals.Headers = Headers + globals.Request = Request + globals.Response = Response }