Skip to content

Conversation

@BelKed
Copy link
Contributor

@BelKed BelKed commented Mar 12, 2025

Manually tested, finally works as intended :)
Inspired by: https://stackoverflow.com/questions/66618136





Important

Implements a keep-alive mechanism in main.ts to prevent Chrome from terminating inactive service workers, addressing issue #173.

  • Behavior:
    • Implements a keep-alive mechanism in main.ts to prevent Chrome from terminating inactive service workers.
    • Uses setInterval to send a keep-alive ping every 4 minutes, less than Chrome's 5-minute timeout.
    • Logs debug messages for keep-alive pings and errors.
  • Environment:
    • The keep-alive mechanism is only activated if VITE_TARGET_BROWSER is set to 'chrome'.
  • Issue Fix:

This description was created by Ellipsis for 19321a9. It will automatically update as commits are pushed.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Reviewed everything up to 19321a9 in 1 minute and 34 seconds

More details
  • Looked at 35 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 5 drafted comments based on config settings.
1. src/background/main.ts:98
  • Draft comment:
    Consider extracting the 4-minute interval into a constant/config to improve maintainability.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50%
    None
2. src/background/main.ts:93
  • Draft comment:
    Verify that the alarm exists before getting it to avoid unexpected errors.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50%
    None
3. src/background/main.ts:83
  • Draft comment:
    Ensure VITE_TARGET_BROWSER reliably detects Chrome. Consider a fallback for cases when this env variable is undefined.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50%
    None
4. src/background/main.ts:89
  • Draft comment:
    Using browser.alarms.get as a keep-alive 'ping' is a neat hack, but ensure it indeed triggers enough activity to prevent termination in production.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50%
    None
5. src/background/main.ts:102
  • Draft comment:
    Consider storing the interval ID from setInterval in case you need to clear it for any cleanup in the future.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50%
    None

Workflow ID: wflow_AR9i3yrhNpmLdSN9


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

@ErikBjare ErikBjare merged commit 23f34ba into ActivityWatch:master Mar 12, 2025
4 checks passed
@ErikBjare
Copy link
Member

Nice, thanks!

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.

Chrome: Service worker goes inactive after user inactivity

2 participants