Skip to content

Fix delayed WebSocket reconnection when screen is turned off#12

Open
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-mobile-chrome-reconnection-delay
Open

Fix delayed WebSocket reconnection when screen is turned off#12
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-mobile-chrome-reconnection-delay

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 12, 2026

Mobile Chrome aggressively throttles setTimeout when the page is hidden (screen off), causing reconnection delays of minutes instead of seconds.

Changes

  • Visibility API listener: On visibilitychangevisible, immediately calls reconnect() if the socket is not OPEN, bypassing any throttled timers
  • Cleanup: Removes the listener on close() to prevent reconnection after intentional closure
  • Guard: Only runs in browser environments (typeof document !== 'undefined'); no-op in Node.js

Copilot AI and others added 2 commits April 12, 2026 09:08
…on mobile Chrome

When the screen is turned off on mobile Chrome, setTimeout timers are
heavily throttled. This causes the reconnecting-websocket to take a very
long time to reconnect when the screen is turned back on.

This fix listens for the Page Visibility API's 'visibilitychange' event
and immediately triggers a reconnection attempt when the page becomes
visible and the WebSocket is not in OPEN state.

Agent-Logs-Url: https://github.com/opensumi/reconnecting-websocket/sessions/79d31669-ef8c-4f3e-9d8d-49f75e371e02

Co-authored-by: bytemain <[email protected]>
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@bytemain bytemain marked this pull request as ready for review April 12, 2026 09:27
@bytemain bytemain changed the title Fix delayed WebSocket reconnection on mobile Chrome when screen is turned off Fix delayed WebSocket reconnection when screen is turned off Apr 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants