fix(cua-driver): keep remote debugging enabled when a restart is needed - #2910
Merged
f-trycua merged 1 commit intoAug 5, 2026
Merged
Conversation
Chromium's "Allow remote debugging for this browser instance" persists a preference; the browser opens the endpoint when it acts on that preference. On a default user-data-dir that is at next launch, not immediately. Measured on Chrome 151: with the checkbox enabled by hand and left enabled, no listener appeared for 25s and no DevToolsActivePort was written — then a restart with no --remote-debugging-port flag produced both at once. The setup path treated the missing endpoint as failure and rolled the toggle back, erasing the preference moments before the restart that would have activated it. The route could not succeed on such a profile no matter how reliably it navigated. Treat that state as what it is: armed, not broken. Keep the preference, close the temporary tab, and refuse with the single action the caller has to take. The refusal carries restart_required so a caller can branch on it rather than parse prose. Genuine failures still roll back exactly as before. Note this only arises where the endpoint does not open immediately. On a non-default user-data-dir the same toggle opens a listener within the existing 6s window and setup now completes outright — verified end to end on Chrome 151, with browser_prepare returning prepared: true after navigating, matching the exact checkbox, toggling it and closing its tab. The restart-required branch itself is reasoned from the measurement above rather than re-observed after the change; the condition needs a default user-data-dir profile with debugging off to reproduce. It is strictly safer than the previous behaviour either way, since rolling back a persisted preference cannot be correct. Refs #2892 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017zpeGjLTLSALtHsuxKLkNp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #2899 (which is stacked on #2895). Review order: 2895 → 2899 → this.
The bug
setup_existing_profile_endpointtoggles "Allow remote debugging for this browser instance", polls ~6s for a loopback endpoint, and on timeout rolls the toggle back.But that checkbox persists a preference. On a default user-data-dir, Chrome acts on it at next launch — not immediately. Measured on Chrome 151, enabling it by hand and leaving it enabled:
Then a restart, with no
--remote-debugging-portflag:So the rollback erased the setting moments before the restart that would have activated it. On such a profile the route could not succeed however reliably it navigated.
The change
Treat that state as armed rather than broken: keep the preference, close the temporary tab, and refuse with the one action the caller must take. The refusal carries
restart_required: trueplus the side-effect record, so a caller can branch on the field instead of parsing prose. Genuine failures still roll back unchanged — the new branch is guarded onenabled_remote_debugging && code == BrowserRequiresSetup.What is verified, and what is not
Verified end to end on Chrome 151: on a non-default user-data-dir the same toggle opens a listener inside the existing 6s window, and setup now completes outright — navigate, match the exact checkbox, toggle, close the tab, attach:
{"action":"attached_existing_profile","prepared":true, "endpoint_ownership":{"detail":"new PID-owned approval listener correlated with exact setup"}, "side_effects":{"enabled_remote_debugging":true,"closed_setup_page":true}}That is the first time this route has worked at all on Linux, and it comes from #2899's navigation fix.
Not re-observed after the change: the restart-required branch itself. Reproducing it needs a default-user-data-dir profile with debugging currently off, and the profile I measured it on now has debugging enabled. The branch is reasoned from the measurement above. It is strictly safer than the previous behaviour regardless, since rolling back a persisted preference cannot be correct.
Related finding
Chrome ≥136 ignores
--remote-debugging-porton the default user-data-dir (verified: same flag, same build, listener only appears with a non-default--user-data-dir). That makes this checkbox the only sanctioned route to CDP on a real user profile — which is why the rollback mattered enough to chase.Tests: 229 passing.
Refs #2892
🤖 Generated with Claude Code
https://claude.ai/code/session_017zpeGjLTLSALtHsuxKLkNp