JacobLinCool / JacobLinCool/fetch-impl

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

Aperta
#20 0 commenti 1 reazione 1 assegnatario Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
TypeScript
Stelle
2
Fork
1
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

> 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);
})
```

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.