Skip to content

fix(extension): reconnect via chrome.idle on OS resume / screen unlock#1737

Open
Benjamin-eecs wants to merge 1 commit into
jackwener:mainfrom
Benjamin-eecs:fix/extension-idle-reconnect
Open

fix(extension): reconnect via chrome.idle on OS resume / screen unlock#1737
Benjamin-eecs wants to merge 1 commit into
jackwener:mainfrom
Benjamin-eecs:fix/extension-idle-reconnect

Conversation

@Benjamin-eecs

@Benjamin-eecs Benjamin-eecs commented May 24, 2026

Copy link
Copy Markdown
Contributor

Description

The Browser Bridge extension can stay disconnected after Chrome resumes from long sleep. The 24-second keepalive alarm is the only reconnect trigger today, and Chrome may suspend the MV3 service worker across deep sleep so that alarm tick is skipped past system resume. The extension then stays idle until the user manually toggles it off/on in chrome://extensions.

Add a chrome.idle.onStateChanged listener that calls connect() when the state transitions to active. This is the documented wake signal Chrome delivers on screen unlock and OS resume, and it wakes the suspended service worker directly rather than relying on the next alarm tick.

Related issue: fixes #1735

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 🌐 New site adapter
  • 📝 Documentation
  • ♻️ Refactor
  • 🔧 CI / build / tooling

Checklist

  • I ran the checks relevant to this PR
  • I updated tests or docs if needed
  • I included output or screenshots when useful

Screenshots / Output

Verified locally on Chrome for Testing 149 (macOS 15) with the patched extension loaded next to the unpatched release in a separate profile. chrome.idle.onStateChanged fired on real OS idle transition and the service worker's listener received the event; the existing connect() path then re-established the daemon WebSocket.

@Benjamin-eecs Benjamin-eecs marked this pull request as ready for review May 24, 2026 11:56
Copilot AI review requested due to automatic review settings May 24, 2026 11:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the reliability of the OpenCLI Browser Bridge extension by ensuring it reconnects to the daemon after OS resume and screen unlock, addressing cases where MV3 service worker suspension can cause the existing keepalive alarm-based reconnect to be skipped.

Changes:

  • Add a chrome.idle.onStateChanged listener to trigger connect() when the browser transitions to the active state.
  • Add the "idle" permission to the extension manifest to enable the idle API.
  • Update the built service worker output (dist/background.js) to include the new reconnect hook.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.

File Description
extension/src/background.ts Registers an idle.onStateChanged listener to reconnect on active after resume/unlock.
extension/manifest.json Adds the required "idle" permission for the idle API.
extension/dist/background.js Built output updated to reflect the new idle-based reconnect logic.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Benjamin-eecs Benjamin-eecs force-pushed the fix/extension-idle-reconnect branch 4 times, most recently from dc20ed3 to 1a716ee Compare May 26, 2026 22:48
@Benjamin-eecs Benjamin-eecs changed the title fix(extension): reconnect via chrome.idle on OS resume / screen unlock (fixes #1735) fix(extension): reconnect via chrome.idle on OS resume / screen unlock May 27, 2026
@Benjamin-eecs Benjamin-eecs force-pushed the fix/extension-idle-reconnect branch 4 times, most recently from 0b48f61 to 0e13776 Compare June 1, 2026 18:00
@Benjamin-eecs Benjamin-eecs force-pushed the fix/extension-idle-reconnect branch 7 times, most recently from b9aadbf to 368ae69 Compare June 7, 2026 02:37
@Benjamin-eecs Benjamin-eecs force-pushed the fix/extension-idle-reconnect branch 2 times, most recently from d59d819 to 082a91f Compare June 17, 2026 14:41
@Benjamin-eecs Benjamin-eecs force-pushed the fix/extension-idle-reconnect branch 2 times, most recently from e39c595 to a410667 Compare June 22, 2026 09:58
The 24-second keepalive alarm is the only reconnect trigger today, but
Chrome may suspend the MV3 service worker across deep sleep so an alarm
tick can be skipped past system resume. Add chrome.idle.onStateChanged
to wake the worker on the first active signal after lock or sleep.

Fixes jackwener#1735
@Benjamin-eecs Benjamin-eecs force-pushed the fix/extension-idle-reconnect branch from a410667 to ad3073d Compare July 2, 2026 14:50
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.

[Bug]:Browser Bridge extension stops reconnecting after Chrome remains open overnight

2 participants