Skip to content

Fixes random extension disconnects#37

Merged
naps62 merged 4 commits intomainfrom
auto-reconnect
Jun 23, 2025
Merged

Fixes random extension disconnects#37
naps62 merged 4 commits intomainfrom
auto-reconnect

Conversation

@naps62
Copy link
Copy Markdown
Member

@naps62 naps62 commented Jun 23, 2025

This was a longstanding bug where browser tabs would ocasionaly get disconnected from the background script, and weirdly would require not one but two or more refreshes to fix.

These apparently are caused by the browser's idle timeout for background scripts, which is enforced more strictly in Manifest v3. There is no manifest option to make the background script persistent, and using a keepalive logic is fallible because the browser will restrict JS execution time for idle pages.

The solution is to automatically reconnect the
contentscript<->background connection on disconnect, and reseting all the appropriate callbacks.

These apparently are caused by the browser's idle timeout for background scripts, which is enforced more strictly in Manifest v3.
There is no manifest option to make the background script persistent,
and using a keepalive logic is fallible because the browser will
restrict JS execution time for idle pages.

The solution is to automatically reconnect the
contentscript<->background connection on disconnect, and reseting all
the appropriate callbacks.
Copilot AI review requested due to automatic review settings June 23, 2025 16:11
@naps62 naps62 added the B-bug Something isn't working label Jun 23, 2025
Copy link
Copy Markdown

Copilot AI left a comment

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 adds automatic reconnection logic between the content script and background script to address intermittent disconnects under Manifest v3 idle timeouts.

  • Removed an obsolete debug log in the inpage script.
  • Refactored the content script to use a recursive connectToBackground function that cleans up and re-establishes streams on disconnect.
  • Added a console log in the background script when setting up provider connections.

Reviewed Changes

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

File Description
src/inpage/index.ts Removed a leftover debug statement logging the provider object.
src/content-script/index.ts Introduced connectToBackground for reconnect logic and updated comments.
src/background/index.ts Added a console.log for when setupProviderConnection is invoked.

@naps62 naps62 added bugfix and removed B-bug Something isn't working labels Jun 23, 2025
@naps62 naps62 merged commit 13dda5f into main Jun 23, 2025
3 of 4 checks passed
@naps62 naps62 deleted the auto-reconnect branch June 23, 2025 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants