feat(cli): add --chrome-arg flag for extra Chromium flags (fixes #2148)#2162
feat(cli): add --chrome-arg flag for extra Chromium flags (fixes #2148)#2162kagura-agent wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: 0b57504 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
This PR is from an external contributor and must be approved by a stagehand team member with write access before CI can run. |
There was a problem hiding this comment.
1 issue found across 3 files
Confidence score: 3/5
- There is a concrete regression risk in
packages/cli/src/index.ts: the daemon compatibility check does not account for--chrome-argchanges, so users can silently keep running with stale Chromium flags. - Given the issue’s medium severity (6/10) and high confidence (8/10), this carries real user-facing behavior risk even though the change set is small.
- This is likely fixable without broad redesign, but merge confidence is moderate until daemon reuse logic reflects flag changes.
- Pay close attention to
packages/cli/src/index.ts- ensure daemon compatibility/restart logic includes--chrome-argso updated Chromium flags are applied.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/cli/src/index.ts">
<violation number="1" location="packages/cli/src/index.ts:1514">
P2: Daemon compatibility check ignores `--chrome-arg` changes, silently reusing an existing daemon with stale Chromium flags.</violation>
</file>
Architecture diagram
sequenceDiagram
participant User as CLI User
participant CLI as CLI Entry (index.ts)
participant Daemon as Daemon Process
participant LocalStrategy as Local Strategy (local-strategy.ts)
participant Core as Core Launch (launchLocalChrome)
Note over User,Core: NEW: --chrome-arg flag flow
User->>CLI: browse open --chrome-arg=--no-focus-on-navigate --chrome-arg=--disable-gpu
CLI->>CLI: Parse --chrome-arg as repeatable string[]
alt Direct --ws connection
CLI->>CLI: Build localBrowserLaunchOptions with chromeArgs
Note over CLI: args: ["--no-focus-on-navigate", "--disable-gpu"]
CLI->>Core: init() with localBrowserLaunchOptions.args
else Daemon path
CLI->>Daemon: spawn daemon with --chrome-arg forwarded
Daemon->>Daemon: runDaemon(session, headless, chromeArgs)
Daemon->>LocalStrategy: resolveLocalStrategy({ extraArgs: chromeArgs })
alt Isolated strategy
LocalStrategy->>LocalStrategy: Merge extraArgs into localLaunchOptions.args
LocalStrategy-->>Daemon: localLaunchOptions with args array
else Isolated-fallback strategy
LocalStrategy->>LocalStrategy: Merge extraArgs into localLaunchOptions.args
LocalStrategy-->>Daemon: localLaunchOptions with args array
else CDP-attach strategy
Note over LocalStrategy: extraArgs ignored (attaching to existing browser)
LocalStrategy-->>Daemon: No args in localLaunchOptions
end
Daemon->>Core: launchLocalChrome(localLaunchOptions)
Core->>Core: Spread args into chromeFlags[]
Core-->>Daemon: Chrome launched with extra flags
Daemon-->>CLI: Ready for commands
CLI->>Daemon: sendCommand with chromeArgs for restart handling
end
Note over User,Core: Failure handling preserves chromeArgs
alt Daemon restart on failure
Daemon->>Daemon: ensureDaemon(session, headless, chromeArgs)
Daemon-->>CLI: Restarted with same chrome flags
end
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
| } | ||
|
|
||
| async function ensureDaemon(session: string, headless: boolean): Promise<void> { | ||
| async function ensureDaemon(session: string, headless: boolean, chromeArgs: string[] = []): Promise<void> { |
There was a problem hiding this comment.
P2: Daemon compatibility check ignores --chrome-arg changes, silently reusing an existing daemon with stale Chromium flags.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/cli/src/index.ts, line 1514:
<comment>Daemon compatibility check ignores `--chrome-arg` changes, silently reusing an existing daemon with stale Chromium flags.</comment>
<file context>
@@ -1509,7 +1511,7 @@ async function stopDaemonAndCleanup(session: string): Promise<void> {
}
-async function ensureDaemon(session: string, headless: boolean): Promise<void> {
+async function ensureDaemon(session: string, headless: boolean, chromeArgs: string[] = []): Promise<void> {
const wantMode = await getDesiredMode(session);
assertModeSupported(wantMode);
</file context>
|
Re: cubic-dev-ai's daemon compatibility concern — valid point that the daemon reuse check doesn't account for |
Summary
Add a repeatable
--chrome-argglobal flag to thebrowseCLI so users can pass extra Chromium flags to the local browser.Closes #2148
Problem
The
browseCLI's headed mode steals window focus on every command because there is no way to pass Chromium flags like--no-focus-on-navigateor--disable-backgrounding-occluded-windows. The coreLocalBrowserLaunchOptionsSchemaalready supports anargsarray, andlaunch/local.tsalready spreadsopts.argsintochromeFlags— but the CLI layer never exposes this to end users.Changes
packages/cli/src/local-strategy.tsargs?: string[]to the CLI'sLocalBrowserLaunchOptionsinterfaceextraArgs?: string[]toResolveLocalStrategyOptionsextraArgsintolocalLaunchOptionsfor theisolatedandisolated-fallbackpaths (CDP-attach paths are unaffected — args are irrelevant when attaching to an existing browser)packages/cli/src/index.tschromeArg?: string[]toGlobalOpts--chrome-arg <arg>repeatable option to the programrunCommand→ensureDaemon→ daemon spawn →runDaemon→resolveLocalStrategy--wsconnection path.changeset/expose-chrome-args-cli.mdUsage
Testing
runCommand→ensureDaemon(spawn with--chrome-argforwarded) →runDaemon→resolveLocalStrategy→localLaunchOptions.args→ core'slaunchLocalChrome→chromeFlagsarraySummary by cubic
Added a repeatable
--chrome-argflag to thebrowseCLI to pass extra Chromium flags to the local browser. This helps stop window focus stealing in headed mode and allows other Chrome tuning.--chrome-arg <arg>is repeatable and forwarded through the daemon, direct--wsconnections, and local strategy resolution.args), enabling options like--no-focus-on-navigateand--disable-backgrounding-occluded-windows.Written for commit 0b57504. Summary will update on new commits. Review in cubic