Skip to content

fix: add retry and reconnection logic for popup resilience#37

Merged
whatasoda merged 6 commits intomainfrom
fix/popup-connection-resilience
Jan 1, 2026
Merged

fix: add retry and reconnection logic for popup resilience#37
whatasoda merged 6 commits intomainfrom
fix/popup-connection-resilience

Conversation

@whatasoda
Copy link
Copy Markdown
Owner

Summary

  • Add retry logic with exponential backoff to sendMessage for handling MV3 service worker termination
  • Add automatic port reconnection support for popup-to-background communication
  • Add error handling to all async operations in popup hooks

Problem

When the popup is opened after a period of inactivity, it sometimes shows nothing. This is caused by:

  1. MV3 service workers being terminated after ~5 minutes of idle
  2. No error handling in messaging functions when service worker is unavailable
  3. No reconnection logic for port connections

Changes

Core retry logic (src/core/retry/)

  • RetryConfig interface with configurable max attempts, delays, and backoff
  • calculateBackoffDelay for exponential backoff calculation
  • isRetryableError to detect recoverable Chrome messaging errors

Messaging infrastructure (src/infrastructure/chrome/)

  • MessagingError class with typed error codes
  • sendMessage now includes automatic retry with exponential backoff
  • createPopupConnection for managed port connections with auto-reconnect

Popup error handling (src/popup/)

  • usePopupPort now uses createPopupConnection for resilient connections
  • Added .catch() handlers to all async operations
  • Fallback behavior when operations fail

Test plan

  • Open popup immediately after browser start - should work normally
  • Wait 5+ minutes, then open popup - should display tabs (with retry if needed)
  • Verify keyboard shortcuts still work after idle period
  • Run bun run test - all tests pass
  • Run bun run build - build succeeds

🤖 Generated with Claude Code

whatasoda and others added 6 commits January 1, 2026 16:15
- Add RetryConfig interface with maxAttempts, baseDelayMs, maxDelayMs, backoffMultiplier
- Add calculateBackoffDelay function for exponential backoff
- Add isRetryableError to detect recoverable Chrome messaging errors
- Add delay utility function
- Add comprehensive unit tests

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add MessagingError class with typed error codes
- Add isServiceWorkerError detection helper
- Add classifyError for error classification
- Add toMessagingError utility for error conversion

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add sendMessageWithRetry with exponential backoff
- Detect service worker termination errors and retry
- Handle ERROR response type from background
- Fix MessagingError to properly use Error.cause

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add PopupConnection interface for managed port connections
- Add createPopupConnection with automatic reconnection
- Implement onDisconnect handler with exponential backoff
- Add connection state tracking via callbacks

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Update usePopupPort to use createPopupConnection with reconnection
- Add .catch() to captureCurrentTab in useCaptureScreenshot
- Add .catch() to getLaunchInfo/clearLaunchInfo in useDisplayModeControl
- Add error handling to switchToTab in popup entry
- Add fallback to "all" mode when display mode detection fails

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@whatasoda whatasoda merged commit 805056b into main Jan 1, 2026
1 check passed
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.

1 participant