iPhone Back skipped my site: pushState came after the tap
On my iPhone, Back threw me out of my own site and ignored every open picture. The test suite was green the whole time, because no test ever pressed the real Back button.

In this story3 sections
I opened a story on my own site on my iPhone, read a few lines, and swiped back. I expected the stories page. I got Chrome's start screen. The whole site was gone, as if I had never been there.
Then I tried a case study. I tapped a picture to see it full size and went Back to close it. The picture didn't close. The page underneath it left instead.
Back is the gesture I use most on a phone. Nobody reads a label for it, nobody thinks about it. So when an overlay ignores Back, it doesn't feel like a missing feature. It feels like the site is broken, and by the time you notice, the reader is somewhere else.
Green tests, broken Back
The strange part was the timing. I had just finished a production audit, and the end-to-end suite was green: 301 tests across 5 browser projects, one of them an iPhone 15 profile running WebKit. The audit had even put history under stress, six fast navigations, four Backs, three Forwards, and every step landed on the right page.
So I trusted the green. That was the wrong turn. The tests went Back with Playwright's page.goBack(), which is a script asking the browser to step back. It never touches the browser's own Back button, and that button is where the problem lived.
WebKit runs every browser on an iPhone, Chrome included. It watches the history entries a page adds with pushState, and if an entry wasn't made during a user gesture, like a tap, Back skips over it. That's a fair defence against pages that trap you with fake entries. My site wasn't trapping anyone, but it looked exactly like it was. Astro's router adds its history entry after it has fetched the next page and swapped it in, long after my finger has left the glass. To WebKit, every one of those entries came from nowhere, so Back jumped over all of them and out of the site.
The audit report had even said it, in its list of remaining risks: touch was emulated, and no physical iPhone was used. I read that line and moved on.
Making the entry inside the tap
The fix was to make the entry while the tap is still a tap. Astro fires an event inside the click, before it fetches anything, and that's where history-gesture.ts now adds the entry:
document.addEventListener("astro:before-preparation", (event) => { pushNow(event.to.href); // still inside the tap});When the router's own pushState for that address arrives later, it becomes a replaceState. One entry, made at the right moment.
Overlays needed the same idea and one more step. On a phone, the case lightbox, a work's detail and its full-page reader each get their own history entry on the same address, made at the tap. Back lands on the entry below and closes whatever sits above it. Close, Escape or a tap outside steps back over the entry quietly, so no dead entry is left behind. On desktop, Back still leaves the page, as it always has.
The last snag was order. My Back handler had to run before the router's, and I assumed a capture listener would. In Chromium it doesn't: listeners on the window run in the order they were added, capture or not. So overlay-back.ts registers its listener in the page's <head>, before the router can add its own.
Checking it on a real iPhone
Then I did the part no test could do for me. On my iPhone I opened a case picture and pressed Back: the picture closed and the page stayed. I opened a project, went to its full page, and stepped Back twice. Both worked.
- Tests green while iPhone Back was broken
- 301
- Browser projects in the suite
- 5
- Back flows checked on my own iPhone
- 2
If your site routes pages or opens overlays in the browser, add the history entry in the tap itself, not after the fetch. And read a passing goBack() for what it is: proof your code handles history, not proof the Back button works. For that, someone has to hold a phone and press it.



