> ## Content Index
> Fetch the complete content index at: https://debugly.dev/llms.txt
> Use this file to discover other available public pages before exploring further.

# Why AbortSignal.timeout() Can Outlast the Clock
- URL: https://debugly.dev/abortsignal-timeout-active-time-bfcache/
- Published: 2026-11-07T10:20:00.000Z
- Updated: 2026-11-07T10:20:00.000Z
- Description: A browser timeout counts active time. Check what happens after a back/forward cache restore and give real deadlines a separate check.
- Author: Rohit Bhadani
- Tags: JavaScript, Frontend, Debugging

You set a five-second `AbortSignal.timeout()` on a page, navigate away, and come back half a minute later. If the browser restored the page from the back/forward cache, the signal can still be un-aborted. The five seconds were a budget for **active time**, and the cached page wasn't spending it. If you need a deadline that also expires while the page is away, keep that deadline separately and check it on return.

*This is an AI-prepared, documentation-based explainer, not a personally reproduced incident. The examples are illustrative and were not run in a browser. See the* [*editorial policy*](https://debugly.dev/editorial-policy/)*.*

## The stopwatch belongs to the page

The [DOM standard](https://dom.spec.whatwg.org/?ref=debugly.dev#dom-abortsignal-timeout) creates the signal and asks HTML to run steps after a timeout. The [HTML algorithm](https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html?ref=debugly.dev#run-steps-after-a-timeout) counts time while a window's document is fully active, or while a worker isn't suspended. That time needn't be consecutive. After the wait, the DOM algorithm queues the task that aborts the signal with a `TimeoutError`. That last step matters too: a busy event loop can delay when your code sees the abort.

The back/forward cache is a good way to see the distinction. It can preserve the page and its JavaScript state during history navigation. When the same page returns, its old signal can still be there with active time left to spend. A hidden tab is a different observation: a tab switch alone doesn't prove that the document became inactive or that its execution context was suspended. And a reload creates new state entirely. If your code makes a new signal on reload, you're looking at a new stopwatch.

## Check restoration before chasing the network

Use a small page with no fetch in flight for the first check. That takes the endpoint out of the investigation and avoids assuming a live request behaves the same way across browsers. On a fully loaded test page, attach this illustrative probe, start a timeout, navigate to another page, wait longer than the requested delay, then use Back. Let the click handler do the starting so you can navigate away immediately afterwards.

```
let probe;
document.querySelector("#start").addEventListener("click", () => {
  probe = { startedAt: Date.now(), signal: AbortSignal.timeout(20_000) };
});

window.addEventListener("pageshow", (event) => {
  if (!probe) return;
  console.log({
    restored: event.persisted,
    elapsedMs: Date.now() - probe.startedAt,
    aborted: probe.signal.aborted,
    reason: probe.signal.reason?.name
  });
});
```

A [persisted pageshow](https://web.dev/articles/bfcache?ref=debugly.dev) indicates a cache restoration. If the elapsed time is over 20 seconds and the restored signal hasn't aborted, the two clocks are doing different jobs. If there's no probe state after Back, check for a fresh load before drawing any conclusion about the timer. If the signal is already aborted, check how much active time passed before navigation and test the target browser's lifecycle behavior. A non-restored load, a long task, and a cached restore are three different test cases. None is evidence that the server took 20 seconds.

## Give the deadline its own job

For a lookup where you want to give the current page a short wait budget, a timeout signal is a useful fit. For a quote that expires at a specific instant, store the deadline independently of the signal. On `pageshow`, and before a retry or before applying a late result, compare the current time to that deadline. If it has expired, show stale state or fetch a fresh quote instead of reusing the old one. A client timestamp is useful for the UI but `Date.now()` can move if the system clock changes. The server should enforce expiry when it affects the operation itself.

A wall deadline check doesn't execute while a page is frozen. It gives the next piece of code that runs a way to reject stale work. And aborting the client's fetch isn't proof that the server stopped or rolled back a write. For a request that may have changed state, reconcile its outcome before retrying. Debugly's [client disconnect walkthrough](https://debugly.dev/nodejs-request-signal-cancel-fetch-client-disconnect/) covers that separate cancellation boundary on the server.

Keep two regression cases: a normal active page that runs out of wait time, and a restored page that must refuse to use an expired result. The first checks the signal. The second checks the promise you made to the user. A single “wait five seconds” test can't tell you whether you kept both.