My problem:
I am currently trying to send several fetch()
requests to a url without having to wait for the server's response.
The exact use case is to build a small chrome extension that increase a counter on an external server (which I do not have control on) that increments on GET requests.
But, for the sake of UX, I would want to do this as quickly as possible.
What I tried :
My first try was to cancel the fetch after 100 millisec.
This works OK with a good connection and quick computer but if I do not have both, the fetch() is aborted too soon : the request is never sent.
Here is the code I have so far :
let controller = new AbortController();
let timer = setTimeout(() => controller.abort(), 100);
await fetch(url, {signal: controller.signal}).catch(err => {
if (err.name === 'AbortError') {
}
});
clearTimeout(timer);
Question:
Is there a way to know when a fetch has passed the "send request" part of the fetch so I can abort it right there ?