Skip to content

browser: fix macOS Chrome discovery and timeout=/url= prefix-stacking crash#1

Open
dywongcloud wants to merge 1 commit into
AnEntrypoint:mainfrom
dywongcloud:fix/macos-chrome-and-timeout-url-stacking
Open

browser: fix macOS Chrome discovery and timeout=/url= prefix-stacking crash#1
dywongcloud wants to merge 1 commit into
AnEntrypoint:mainfrom
dywongcloud:fix/macos-chrome-and-timeout-url-stacking

Conversation

@dywongcloud

Copy link
Copy Markdown

Summary

Two real, live-hit bugs in the native CDP browser verb (crates/agentplug-host/src/browser.rs):

  1. macOS Chrome discovery missing. find_chrome() only ever checked /usr/bin/google-chrome+chromium (Linux) or Program Files (Windows) — no macOS app-bundle path existed, so every browser dispatch on a stock macOS install (Chrome not on PATH, which is normal for a Chrome.app install) failed with no Chrome found; install Google Chrome or Chromium. Adds the standard system-wide and per-user /Applications/*.app/Contents/MacOS/* candidates (Chrome + Chromium, for parity with the existing Linux chromium fallback) as additional candidates only — existing Linux/Windows/PATH checks are untouched.

  2. timeout= + url= prefix stacking crash. Stacking a timeout=<ms> prefix line in front of url= (e.g. timeout=30000\nurl=http://x/\n<script>) crashed instantly with SyntaxError: Unexpected token ':', before any navigation ran. Root cause: timeout= was a documented stackable dispatch prefix but nothing in browser.rs ever recognized it — strip_mode_prefix only knows capture/profile/trace, and parse_body only recognizes url=/a bare http(s):// URL as literally the body's first token. So the entire remaining text, including the real url=... line, fell through and was evaluated as raw JS. url=http://x/ is invalid as a bare JS statement: it tokenizes as the assignment expression url = http (the following // is lexed as a line comment) immediately followed by a stray : left over from http: — exactly the reported syntax error. Fixed by giving timeout= its own prefix-stripper and looping it together with strip_mode_prefix in run() so mode and timeout compose in either order before parse_body ever sees the url=/script remainder.

Test plan

  • cargo build --release — clean compile, zero warnings
  • Added unit tests in crates/agentplug-host/src/browser.rs covering: macOS chrome discovery (real filesystem check), timeout=+url= stacking, url= alone (regression), and both stacking orders of mode+timeout+url
  • Added a real end-to-end test that drives actual Chrome over CDP with the exact previously-crashing timeout=30000\nurl=...\nreturn 1+1; body and confirms correct navigation + eval result
  • cargo test -p agentplug-host — 6/6 passing, including the live Chrome test

🤖 Generated with Claude Code

… crash

Two real, live-hit bugs in the native CDP browser verb:

1. find_chrome() only ever checked /usr/bin/google-chrome+chromium (Linux)
   or Program Files (Windows), with no macOS app-bundle path -- every
   browser dispatch on a stock macOS install with Chrome only on PATH via
   nothing (a normal Chrome.app install adds nothing to PATH) failed with
   "no Chrome found; install Google Chrome or Chromium". Adds the standard
   system-wide and per-user /Applications/*.app/Contents/MacOS/* candidates
   (Chrome + Chromium for parity with the existing Linux chromium
   fallback), purely additive -- existing Linux/Windows/PATH checks are
   untouched.

2. Stacking a `timeout=<ms>` prefix line in front of `url=` (e.g.
   `timeout=30000\nurl=http://x/\n<script>`) crashed instantly with
   `SyntaxError: Unexpected token ':'`, before any navigation ran. Root
   cause: `timeout=` was documented as a stackable dispatch prefix but
   nothing in browser.rs ever recognized it -- strip_mode_prefix only
   knows capture/profile/trace, and parse_body only recognizes url=/a bare
   http(s):// URL as literally the body's first token. So the entire
   remaining text, including the real `url=...` line, fell through to be
   evaluated as raw JS. `url=http://x/` is invalid as a bare JS statement:
   it tokenizes as the assignment expression `url = http` (the following
   `//` is lexed as a line comment) immediately followed by a stray `:`
   left over from `http:`, producing exactly the reported syntax error.
   Fixed by giving `timeout=` its own prefix-stripper and looping it
   together with strip_mode_prefix in run() so mode and timeout compose in
   either order before parse_body ever sees the url=/script remainder --
   `timeout=`+`url=` (and `url=`+mode, mode+`timeout=`, all three stacked
   in any order) now all resolve identically to using any single prefix
   alone.

Verified with new unit tests covering both bugs, including a real
end-to-end test that drives actual Chrome over CDP with the exact
previously-crashing stacked-prefix body and confirms correct
navigation + eval result (`cargo test -p agentplug-host`, 6/6 passing).
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