Skip to content

How to prevent hanging chrome-headless-shell processes eating a lot of CPU / battery? #378

@borekb

Description

@borekb

I'm using agent-browser with Claude Code and it works great but sometimes I kill the session without realizing that the agent didn't have a chance to close it via agent-browser close (or the agent can make a mistake by not calling this command).

When this happens, chrome-headless-shell processes remain running indefinitely and sometimes consume a lot of CPU / battery without me realizing it.

For example:

$ ps aux | grep chrome-headless
USER    PID    %CPU  %MEM  ELAPSED   COMMAND
borekb  44028    0.0  0.2  19:54:59  chrome-headless-shell (main)
borekb  44054    0.0  0.1  19:54:59  chrome-headless-shell (network)
borekb  44055    6.8  0.5  19:54:59  chrome-headless-shell (renderer)
borekb  92158  519.2  0.8  01:43:06  chrome-headless-shell (gpu-process)

Is there a way to deal with this, like a global timeout for new sessions that are left hanging? Claude Code suggested I add a SessionEnd hook but I wanted to ask wheter there's a better way to handle this.

Thanks for an awesome tool BTW!


UPDATE: This is the SessionEnd hook that Claude suggested:

.claude/settings.json:

{
  "hooks": {
    "SessionEnd": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "agent-browser close 2>/dev/null || true"
          }
        ]
      }
    ]
  }
}

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