JacobLinCool / JacobLinCool/fetch-impl
TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
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
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Bewertung
Dieses Issue wurde noch nicht bewertet.