You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
WebSocket does not reconnect on Chrome 149 after switching apps on mobile #6804
I am not well versed in the JS side of LiveView so I have not fully verified the LLM diagnosis myself yet, but supposedly Phoenix is left with a stale true value for pageHidden that suppresses re-connection, since the bad flow doesn't emit pagehide/pageshow/visibilitychange (visible).
I was unable to reproduce using the bfcache normally (via the back button). Only when swapping apps on mobile.
changed the title [-]WebSocket dies on Chrome 149 after switching apps on mobile[/-][+]WebSocket does not reconnect on Chrome 149 after switching apps on mobile[/+]on Aug 15, 2026
I'm unable to reproduce on either Android Chrome 151 or 149. I visited phoenixframework.org and the WebSocket does properly reconnect when I switch between apps. Can you try if it happens for you on that same page?
but supposedly Phoenix is left with a stale true value for pageHidden that suppresses re-connection, since the bad flow doesn't emit pagehide/pageshow/visibilitychange (visible)
If the browser really doesn't emit pageshow / visibilitychange, that would be a browser bug. Those should always be emitted when the page becomes active again.
I tried phoenixframework.org and it does not reproduce, although I don't get any error flash at all even when I turn off wifi/data.
Let me try again to see if I can reproduce it with a minimal phoenix project I can share. The app I'm observing the issue on is a PWA so maybe it's related.
I can reproduce this reliably on an installed PWA, and I have on-device traces that I think confirm the pageHidden mechanism described above and narrow the trigger.
One methodological note first, since it may explain the failed reproductions: attaching DevTools prevents Chrome from freezing the page, and freezing appears to be a precondition for the failure. I could only capture this by instrumenting the page over CDP, detaching, reproducing, and then reattaching to read a log persisted to localStorage. With the debugger attached throughout, it never reproduces.
Environment
Device
Motorola moto g power 5G (2024), Android 15
Chrome
151.0.7922.171
App
Installed PWA (WebAPK), not a browser tab
phoenix
1.8.5
phoenix_live_view
1.1.28
Chrome 151 rather than 149, so whatever this is, it is not confined to 149.
Trace of a failing cycle
Recorded by listeners on document (visibilitychange, freeze, resume) and window (focus, blur, pageshow, pagehide), plus a property watch on socket.pageHidden that captures a stack trace on every write. hiddenFor is seconds since the page went hidden.
04:42:43.076 visibilitychange vis=hidden conn=open -> pageHidden = true
04:42:48.614 sock:close code=1006 pageHidden=true
04:43:43.096 freeze vis=hidden conn=closed hiddenFor=60
04:46:35.274 resume vis=visible conn=closed hiddenFor=232 pageHidden STILL true
(no visibilitychange, no pageshow, no pagehide)
04:46:35.310 pageHidden = false <- my own workaround, not framework code
04:46:35.555 focus vis=visible conn=connecting
04:46:35.854 sock:open
The two events that matter:
resume fires. The browser is not silent when the app returns.
visibilitychange does not fire, in either the target phase on document or the capture phase on window. Neither does pageshow or pagehide.
Short background/foreground cycles on the same device behave correctly — visibilitychange fires and the socket recovers on its own:
The difference is the freeze. Short cycles are never frozen and never fail; the failing cycle was frozen after 60s hidden. That matches the reports of this only biting after a long absence.
Terminal state, measured with the app visibly hung on screen
pageHidden: true <-- stale
document.hidden: false
visibilityState: "visible"
connectionState: "closed"
conn: null
connectClock: 2 (unchanged from before backgrounding)
reconnectTimer.tries: 1
channels: ["errored", "closed"], no rejoin scheduled
/health answered in under 400ms throughout, so the server was reachable the whole time.
tries: 1 shows the reconnect timer fired exactly once and then stopped. connectClock never advancing confirms transportConnect() was never reached. The page is fully alive — setTimeout callbacks run normally — there is simply nothing left scheduled that intends to reconnect. Only killing and relaunching the app clears it.
Why it is permanent rather than delayed
this.reconnectTimer=newTimer(()=>{if(this.pageHidden){this.log("Not reconnecting as page is hidden!")this.teardown()return}this.teardown(()=>this.connect())},this.reconnectAfterMs)
The early return calls teardown() with no callback, so it neither reconnects nor reschedules itself. teardown() also noops conn.onclose and nulls this.conn, so onConnClose's scheduleTimeout() cannot fire again either. Recovery then rests entirely on the visibilitychange handler clearing pageHidden — and since v1.8.4 that handler is additionally gated on !this.closeWasClean. When the event never arrives, there is no second path.
I want to be fair to the maintainer position that a browser not emitting visibilitychange is a browser bug — my measurements agree that Chrome is not emitting it. But resumeis emitted, in the same cycle, before focus, so a framework-side recovery is available without relying on the event that goes missing.
Suggestions
Read document.hidden directly when the timer fires, instead of the cached flag. pageHidden is a cache of exactly that value, and reading it at the point of use cannot go stale from a missed event. Smallest possible change, no new listeners:
if(document.hidden){ ... }
Also clear the flag on resume, which is the Page Lifecycle event for precisely this transition and which I measured firing on the failing cycle.
Reschedule while hidden. Even keeping the early return, calling this.reconnectTimer.scheduleTimeout() before returning would make the state recoverable rather than terminal, at the cost of a cheap timer and no network attempt.
Happy to run further instrumented cycles on this device if any specific measurement would help — the harness is still set up.
Activity
[-]WebSocket dies on Chrome 149 after switching apps on mobile[/-][+]WebSocket does not reconnect on Chrome 149 after switching apps on mobile[/+]SteffenDE commentedon Aug 17, 2026
Thank you, I will try to investigate
SteffenDE commentedon Aug 18, 2026
I'm unable to reproduce on either Android Chrome 151 or 149. I visited phoenixframework.org and the WebSocket does properly reconnect when I switch between apps. Can you try if it happens for you on that same page?
If the browser really doesn't emit pageshow / visibilitychange, that would be a browser bug. Those should always be emitted when the page becomes active again.
quintinm-dev commentedon Aug 19, 2026
Oh darn sorry.
I tried phoenixframework.org and it does not reproduce, although I don't get any error flash at all even when I turn off wifi/data.
Let me try again to see if I can reproduce it with a minimal phoenix project I can share. The app I'm observing the issue on is a PWA so maybe it's related.
brocla commentedon Aug 25, 2026
I can reproduce this reliably on an installed PWA, and I have on-device traces that I think confirm the
pageHiddenmechanism described above and narrow the trigger.One methodological note first, since it may explain the failed reproductions: attaching DevTools prevents Chrome from freezing the page, and freezing appears to be a precondition for the failure. I could only capture this by instrumenting the page over CDP, detaching, reproducing, and then reattaching to read a log persisted to
localStorage. With the debugger attached throughout, it never reproduces.Environment
Chrome 151 rather than 149, so whatever this is, it is not confined to 149.
Trace of a failing cycle
Recorded by listeners on
document(visibilitychange,freeze,resume) andwindow(focus,blur,pageshow,pagehide), plus a property watch onsocket.pageHiddenthat captures a stack trace on every write.hiddenForis seconds since the page went hidden.The two events that matter:
resumefires. The browser is not silent when the app returns.visibilitychangedoes not fire, in either the target phase ondocumentor the capture phase onwindow. Neither doespageshoworpagehide.Short background/foreground cycles on the same device behave correctly —
visibilitychangefires and the socket recovers on its own:The difference is the
freeze. Short cycles are never frozen and never fail; the failing cycle was frozen after 60s hidden. That matches the reports of this only biting after a long absence.Terminal state, measured with the app visibly hung on screen
/healthanswered in under 400ms throughout, so the server was reachable the whole time.tries: 1shows the reconnect timer fired exactly once and then stopped.connectClocknever advancing confirmstransportConnect()was never reached. The page is fully alive —setTimeoutcallbacks run normally — there is simply nothing left scheduled that intends to reconnect. Only killing and relaunching the app clears it.Why it is permanent rather than delayed
The early return calls
teardown()with no callback, so it neither reconnects nor reschedules itself.teardown()also noopsconn.oncloseand nullsthis.conn, soonConnClose'sscheduleTimeout()cannot fire again either. Recovery then rests entirely on thevisibilitychangehandler clearingpageHidden— and since v1.8.4 that handler is additionally gated on!this.closeWasClean. When the event never arrives, there is no second path.I want to be fair to the maintainer position that a browser not emitting
visibilitychangeis a browser bug — my measurements agree that Chrome is not emitting it. Butresumeis emitted, in the same cycle, beforefocus, so a framework-side recovery is available without relying on the event that goes missing.Suggestions
Read
document.hiddendirectly when the timer fires, instead of the cached flag.pageHiddenis a cache of exactly that value, and reading it at the point of use cannot go stale from a missed event. Smallest possible change, no new listeners:Also clear the flag on
resume, which is the Page Lifecycle event for precisely this transition and which I measured firing on the failing cycle.Reschedule while hidden. Even keeping the early return, calling
this.reconnectTimer.scheduleTimeout()before returning would make the state recoverable rather than terminal, at the cost of a cheap timer and no network attempt.Happy to run further instrumented cycles on this device if any specific measurement would help — the harness is still set up.
Recover the LiveView socket when the app returns to the foreground
SteffenDE commentedon Aug 25, 2026
Upstream issue https://issues.chromium.org/issues/547062449.
SteffenDE commentedon Aug 25, 2026
Thank you @brocla, that analysis was very helpful!
SteffenDE commentedon Aug 25, 2026
Fixed in v1.8.13
Keep the on-device CDP diagnostics harness
Upgrade to phoenix 1.8.13 and drop the parts it made redundant
chore(deps): bump phoenix from 1.8.12 to 1.8.13
chore(deps): update phoenix, phoenix_live_view, bandit, mint, hackney…