JacobLinCool / JacobLinCool/fetch-impl

TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation

Offen
#20 0 Kommentare 1 Reaktion 1 zugewiesene Person Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
TypeScript
Sterne
2
Forks
1
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

> The error "TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation" typically occurs in JavaScript when the fetch function is called with an incorrect this context. The fetch function, as a method of the Window object, expects this to refer to the Window object when it's invoked. If fetch is extracted from window and called in a different context (e.g., as a method of a custom object or without a specific this binding), this error can arise.

When testing [leetcode-query](https://github.com/JacobLinCool/LeetCode-Query) in browser(in fact, it can't work because of CORS), I got above error and searched in Google. Seems it's better to bind globalThis in fetcher/src/fetcher.ts, or you need set custom fetcher like,
```
fetcher.set(async (...args) => {
const res = await window.fetch(...args); // call with right this context
return new Response(res.body, res);
})
```

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.