Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get the proper global object depending on environment to check for existing fetch #956

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}