Skip to content

Reduce offscreen heartbeat frequency to avoid unnecessary service-worker wakeups #3241

Open

Description

@vishalanton16

Description

The offscreen document currently sends a service-worker heartbeat every second, producing approximately 60 messages per minute while idle.

Chrome's documented lifecycle supports a less frequent heartbeat:

  • Service workers normally terminate after 30 seconds of inactivity.
  • Since Chrome 109, messages from offscreen documents reset the idle timer.
  • Since Chrome 114, sending messages through a long-lived connection keeps the worker alive; opening a port alone no longer resets the timer.

Documentation:
https://developer.chrome.com/docs/extensions/develop/concepts/service-workers/lifecycle#idle-shutdown
https://developer.chrome.com/docs/extensions/develop/concepts/service-workers/lifecycle#chrome-109
https://developer.chrome.com/docs/extensions/develop/concepts/service-workers/lifecycle#chrome-114

Reproduction

  1. Launch a browser with the Stagehand extension active.
  2. Instrument the offscreen heartbeat's port.postMessage call with a counter.
  3. Leave the browser idle for 60 seconds.
  4. Observe approximately 60 heartbeat messages.

Proposed behavior

Increase the heartbeat interval from 1 second to 20 seconds. This would reduce scheduled heartbeat messages by 95%, to approximately three per minute, while leaving a nominal 10-second margin below Chrome's idle timeout.

The 20-second interval is a proposed implementation choice, not an interval prescribed by Chrome.

Validation

  • Confirm service-worker state survives at least 70 seconds of inactivity with the debugger detached and without polling the worker.
  • Verify recovery after heartbeat-port disconnection.
  • Preserve serialized offscreen-document creation.
  • Confirm the reduced frequency works across supported Chrome versions.

Activity

  1. Ethereal49 commented on Oct 24, 2026

    @Ethereal49

    Hi — I'd like to take this heartbeat-frequency issue. I will verify the Chrome service-worker lifecycle assumptions, add a focused regression around the heartbeat interval and disconnected-port recovery, and run the extension tests. I will only adopt the 20-second interval if the lifecycle evidence supports it; otherwise I will report the measured boundary before changing behavior. I will use Codex and disclose the tooling in the PR. If someone is already working on it, please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions