The read-only signal
property of the Request
interface returns the AbortSignal
associated with the request.
Request: signal property
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2019.
Value
An AbortSignal
object.
Examples
js
// Create a new abort controller const controller = new AbortController(); // Create a request with this controller's AbortSignal object const req = new Request("/", { signal: controller.signal }); // Add an event handler logging a message in case of abort req.signal.addEventListener("abort", () => { console.log("abort"); }); // In case of abort, log the AbortSignal reason, if any fetch(req).catch(() => { if (signal.aborted) { if (signal.reason) { console.log(`Request aborted with reason: ${signal.reason}`); } else { console.log("Request aborted but no reason was given."); } } else { console.log("Request not aborted, but terminated abnormally."); } }); // Actually abort the request controller.abort();
Specifications
Specification |
---|
Fetch Standard # ref-for-dom-request-signal② |
Browser compatibility
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | ||
signal |
66 | 16 | 57 | 53 | 12.1 | 66 | 57 | 47 | 12.2 | 9.0 | 66 |
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Request/signal