Skip to content

Add Chrome profile and debugging-port options to ts dev proxy --launch - #1728

Draft
ChristianPavilonis wants to merge 8 commits into
mainfrom
feat/1724-dev-proxy-chrome-profile
Draft

ChristianPavilonis wants to merge 8 commits into
mainfrom
feat/1724-dev-proxy-chrome-profile

Conversation

@ChristianPavilonis

Copy link
Copy Markdown
Collaborator

Summary

  • Add --chrome-user-data-dir <DIR> and --chrome-debug-port <PORT> to ts dev proxy --launch chrome. A kept user data directory survives Chrome exit, so a bot challenge solved once in that profile carries over to the next launch. The debugging port lets Playwright connectOverCDP or the Chrome DevTools MCP attach to the proxied browser over loopback.
  • With either option set, the proxy waits until the Chrome it spawned is ready and prints the kept directory and the DevTools endpoint. Any Chrome launch failure then stops the proxy instead of printing a warning. Without the options, --launch chrome behaves exactly as before.

Two deliberate differences from the issue:

  • The path flag is --chrome-user-data-dir, not --chrome-profile. In Chrome, a profile is a subdirectory such as Default inside the user data directory, selected with --profile-directory; Playwright and the DevTools MCP both call the whole directory userDataDir.
  • Every Chrome launch failure is fatal when either option is set, not only a profile that is already in use, because the caller depends on that exact browser.

Changes

File Change
crates/trusted-server-cli/src/commands/dev/proxy/mod.rs New flags. Runs the Chrome preflight before system proxy recovery, CA loading and the bind. Watches for Ctrl-C while a launch waits, cancels the wait and runs the usual interrupt cleanup. Restores Safari state when a launch fails.
crates/trusted-server-cli/src/commands/dev/proxy/config.rs ChromeLaunchOptions. Rejects either option without chrome in --launch, makes the directory absolute, rejects default Chrome and Chromium user data directories, and rejects a debug port equal to --listen.
crates/trusted-server-cli/src/commands/dev/proxy/browser.rs Preflight: creates the directory with mode 0700, re-checks its real path against the defaults, refuses a profile another Chrome holds by reading SingletonLock, and checks the port. Launch: adds --remote-debugging-port, waits for the spawned Chrome's DevTools listening on stderr line (copied through to the proxy's stderr) or, with only a kept directory, for SingletonLock to name the spawned pid. Kills that Chrome on failure.
crates/trusted-server-cli/src/commands/dev/mod.rs Boxes ProxyArgs for Clippy's large_enum_variant, as Command::Audit already does.
Cargo.toml, crates/trusted-server-cli/Cargo.toml, Cargo.lock rustix (process, system) as a direct dependency for the hostname and pid liveness checks without unsafe. It was already in the tree through tempfile and gix; the lockfile only gains the dependency edge.
crates/trusted-server-cli/tests/proxy_cli.rs CLI tests on the real binary, including a fake google-chrome script for fixed-port readiness, early exit, lock-based readiness and Ctrl-C during the wait.
scripts/test-linux-dev-proxy-launch.mjs Manual Linux proof with real, headed Chrome or Chromium in a disposable HOME, CA, NSS database and runtime directory.
docs/guide/ts-dev-proxy.md "Keep a Chrome profile and attach automation" section with the debugging-port warning, the Chrome browser-details row, three troubleshooting rows, and the new proof script.
CHANGELOG.md Unreleased, Added entry.
docs/superpowers/specs/…-design.md, docs/superpowers/plans/…md Design spec and implementation plan.

Closes

Closes #1724

Follow-up filed from this work: #1725, temporary browser profiles leak when the proxy exits before the browser. That predates this change and is not fixed here.

Spec

Spec: docs/superpowers/specs/2026-12-02-1724-dev-proxy-chrome-profile-design.md

The review log has one independent round so far. It found that Chrome writes DevToolsActivePort only for port 0, which the first design relied on, plus five other defects; all are fixed. A second review round is still needed before this leaves draft.

Test plan

  • cargo test-fastly && cargo test-axum (not run; this change is CLI-only)
  • cargo clippy-fastly && cargo clippy-axum (not run; CLI-only)
  • cargo fmt --all -- --check
  • JS tests: cd crates/trusted-server-js/lib && npx vitest run (no JS changes)
  • JS format: cd crates/trusted-server-js/lib && npm run format (no JS changes)
  • Docs format: cd docs && npm run format (changed Markdown checked with Prettier 3.8.1 and docs/.prettierrc; the VitePress build was not run)
  • WASM build: cargo build --package trusted-server-adapter-fastly --release --target wasm32-wasip1 (not run; CLI-only)
  • Manual testing via fastly compute serve (not applicable)
  • Other:
    • ./scripts/test-cli.sh on Linux x86_64: 804 lib tests and all integration tests pass, including 9 in proxy_cli.
    • cargo clippy-cli and host-target cargo clippy --package trusted-server-cli --all-targets --all-features -- -D warnings.
    • ts dev lint domains --changed-vs origin/main and git diff --check origin/main.
    • node scripts/test-linux-dev-proxy-launch.mjs passed on Chromium 155.0.8059.84 and Google Chrome 158.0.8127.36: DevTools endpoint and CDP attach, in-use refusal without a new window, cookie persistence across a relaunch on a fixed port, Chrome outliving the proxy, and recovery from a stale lock after SIGKILL.
    • Not yet done: macOS runtime (CI covers macOS build and unit tests), and the manual proof against a real bot-protected publisher with a Playwright connectOverCDP and Chrome DevTools MCP attach.

Checklist

  • Feature PRs: spec linked above, ending in a review log of two or more agent review rounds (one round so far)
  • Changes follow AGENTS.md conventions
  • No unwrap() in production code — use expect("should ...")
  • Uses log macros (not println!)
  • New code has tests
  • No secrets or credentials committed

Parse --chrome-user-data-dir and --chrome-debug-port, require chrome in
--launch, make the directory absolute, reject default Chrome and Chromium
user data directories, and reject a debug port equal to --listen.

Box ProxyArgs in DevCommand to keep the enum variants balanced.

Refs #1724
With --chrome-user-data-dir, Chrome uses that directory and the proxy
never deletes it. With --chrome-debug-port, Chrome gets
--remote-debugging-port and the proxy waits for DevToolsActivePort, then
prints the http and ws endpoints.

A preflight runs before CA loading and the bind. It creates the user data
directory with mode 0700, refuses a profile another Chrome holds by
reading SingletonLock, removes a stale DevToolsActivePort, and checks
that a non-zero debug port is free.

With either option set, every Chrome launch failure stops the proxy and
kills a Chrome it started. Without them, launch failures stay warnings.

Refs #1724
The manual Linux proof launches real, headed Chrome through
ts dev proxy --launch chrome with a kept user data directory and port 0,
using a disposable HOME, CA and NSS database. It checks the DevTools
endpoint and CDP attach, the in-use refusal, cookie persistence across a
relaunch, and recovery from a stale lock after SIGKILL.

Refs #1724
Add the guide section on keeping a Chrome profile and attaching
automation, with the debugging-port warning, update the Chrome browser
details and troubleshooting rows, describe the Node launch proof, and add
a changelog entry. Include the design spec and implementation plan.

Refs #1724
Chrome writes DevToolsActivePort only for --remote-debugging-port=0, so a
fixed --chrome-debug-port never finished startup. Read the spawned
Chrome's own "DevTools listening on" stderr line instead, copying every
line through to the proxy's stderr. With only --chrome-user-data-dir,
wait for SingletonLock to name the spawned pid, so a Chrome that exits at
startup or hands its URL to another instance is reported.

Re-check the user data directory against the default directories after
creating it, so a path such as not-yet/../.config/google-chrome cannot
reach the real profile, and launch with that canonical path.

Watch for Ctrl-C while the launch waits, cancel the wait, kill the Chrome
still being waited on, and run the usual interrupt cleanup.

Build the missing-launcher messages from CHROME_LAUNCHERS, move trait
imports to module scope, and follow the test message conventions.

Refs #1724
Issue the fixture cookie only during the first launch and require the
first request after the relaunch to send it. Relaunch on a fixed debug
port, and check that Chrome outlives the proxy and still answers CDP.

Refs #1724
Describe readiness from the spawned Chrome, the post-creation default
check and Ctrl-C during launch in the spec, record the review fixes in the
plan, link the profile leak follow-up #1725, and add a troubleshooting row
for Chrome exiting before it is ready.

Refs #1724

This branch has not been deployed

No deployments
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.

Add Chrome profile and debugging-port options to ts dev proxy --launch

1 participant