Morse Code Flashlight β Blink Your Phoneβs Torch
Type a message and use your deviceβs flashlight to blink it out in Morse code. A fun signaling tool for camping or pranks.
UD5 Toolkit
Explore how to cancel fetch requests, handle timeouts, and manage event listeners with the AbortController API.
Start a slow network request and cancel it before it completes.
Set a timeout using AbortSignal.timeout() β the request auto-cancels when the deadline passes.
Launch 3 concurrent requests sharing one AbortController. Cancel them all at once.
Use { signal: controller.signal } in addEventListener to cleanly remove listeners.
fetch() requests, event listeners, streams, or custom async tasks. It provides an AbortSignal object that you pass to abortable APIs. When you call controller.abort(), all operations linked to that signal are immediately cancelled. This is far cleaner than older patterns like manually tracking and rejecting promises.
Pass the signal property into the fetch options:
const controller = new AbortController();
fetch('https://api.example.com/data', { signal: controller.signal })
.then(res => res.json())
.catch(err => {
if (err.name === 'AbortError') {
console.log('Request was cancelled');
}
});
// Later, cancel the request:
controller.abort();
The fetch promise rejects with an AbortError DOMException when aborted.
AbortSignal.timeout(ms) is a static method (added in 2022) that creates a signal which automatically aborts after a specified number of milliseconds. This eliminates the need to manually create a controller and set up a setTimeout to call .abort(). Example:
// Auto-cancel after 3 seconds
fetch(url, { signal: AbortSignal.timeout(3000) });
Supported in Chrome 103+, Firefox 100+, Safari 16+.
signal to multiple fetch() calls (or other abortable operations). A single controller.abort() will cancel all of them at once. This is incredibly useful for cleanup in SPA frameworks β for example, aborting all in-flight requests when a component unmounts or a user navigates away. See Scene 3 above for a live demo.
signal option to addEventListener:
const controller = new AbortController();
element.addEventListener('click', handleClick, { signal: controller.signal });
// Later β removes ALL listeners linked to this signal:
controller.abort();
This is cleaner than removeEventListener because you don't need to keep a reference to the handler function. One abort() call can remove dozens of listeners at once. See Scene 4 above for a live demo.
DOMException whose name property is 'AbortError'. You should always check for this in your catch blocks to distinguish intentional cancellations from actual network failures:
fetch(url, { signal })
.catch(err => {
if (err.name === 'AbortError') {
// Intentional β do nothing or clean up
} else {
// Real error β show user a message
}
});
AbortError is not a real error β it indicates deliberate cancellation, not a problem.
AbortSignal.timeout().AbortSignal.timeout() static method is supported in Chrome 103+, Firefox 100+, and Safari 16+. The signal option in addEventListener has the same broad support as AbortController itself. For legacy browsers, a polyfill is available. In 2025, you can confidently use AbortController in production without transpilation for 98%+ of users.
signal.aborted (a boolean property) to check whether the signal has already been aborted:
if (controller.signal.aborted) {
console.log('Already aborted, skipping operation.');
} else {
fetch(url, { signal: controller.signal });
}
You can also listen for the abort event: signal.addEventListener('abort', callback).
controller.abort() is called, the signal is permanently aborted and cannot be reset. If you need to start a new batch of abortable operations, you must create a new AbortController instance. This is by design β it prevents accidentally reusing a stale signal. Each logical "group" of cancellable operations should get its own AbortController.
Type a message and use your deviceβs flashlight to blink it out in Morse code. A fun signaling tool for camping or pranks.
Type a word and see an animated semaphore figure spelling it out. Also enter flag positions to decode. Scouts and maritime fun.
Listen to and practice the international distress signal: three short blasts. Lifesaving knowledge.
Enter a URL and see its CORS headers. Understand why a fetch fails. Check preflight responses. Clientβside debugger.
See how to implement file upload progress using both fetch and XHR. Realβtime bar and code snippets for your project.
Paste a cURL command and convert it to a fetch() call in JavaScript, Python requests, or Go net/http. Save time.
Translate text into semaphore flag positions and decode semaphore back to letters. Interactive animated flags. For scouts and maritime fans.