I want to be able to cancel requests with fetch API and use new AbortController()
Unfortunately I get an error in the console: AbortController is not defined
// this.aborter = new XMLHttpRequest() no error
this.aborter = new AbortController() error
What might be the reason? I'm using just vanilla JS without any dependencies.
The MDN documentation on AbortController includes an up-to-date table of supported browsers.
The API is still marked as experimental, although it should be well supported in current browsers. Firefox has it since November 2017 (FF 57), and Chrome followed on April 2018 (Chrome 66).
try
this.aborter = new window.AbortController();
I found that on Chrome (v77) it didn't recognise AbortController with specifying it as a window property.
Also, after you call
this.aborter.abort()
you may need to re-initialise
this.aborter = new window.AbortController();
or future fetch statements won't work (the status will be aborted and it will throw an error!).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With