The static AbortSignal.timeout()
method returns an AbortSignal
that will automatically abort after a specified time.
The signal aborts with a TimeoutError
DOMException
on timeout, or with AbortError
DOMException
due to pressing a browser stop button (or some other inbuilt "stop" operation). This allow UIs to differentiate timeout errors, which typically require user notification, from user-triggered aborts that do not.
The timeout is based on active rather than elapsed time, and will effectively be paused if the code is running in a suspended worker, or while the document is in a back-forward cache ("bfcache").
Note: At time of writing there is no way to combine multiple signals. This means you that you can't directly abort a download using either a timeout signal or by calling AbortController.abort()
.