Add configurable local CDP debugging port for Stagehand V3#1522
Conversation
|
Greptile OverviewGreptile SummaryThis PR adds a configurable Changes OverviewThe implementation properly threads the optional
Implementation QualityThe implementation is clean and follows established patterns in the codebase:
Minor IssueOne style issue found: extra space in documentation text ("When set ," should be "When set,"). Confidence Score: 5/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant User
participant V3
participant launchLocalChrome
participant ChromeLauncher as chrome-launcher
User->>V3: new Stagehand({ env: "LOCAL", localBrowserLaunchOptions: { port: 9222 } })
User->>V3: init()
activate V3
V3->>V3: Extract lbo.port from localBrowserLaunchOptions
V3->>launchLocalChrome: launchLocalChrome({ port: 9222, ... })
activate launchLocalChrome
launchLocalChrome->>ChromeLauncher: launch({ port: 9222, chromePath, chromeFlags, userDataDir })
activate ChromeLauncher
ChromeLauncher-->>ChromeLauncher: Start Chrome on specified port 9222
ChromeLauncher-->>launchLocalChrome: { port: 9222, ... }
deactivate ChromeLauncher
launchLocalChrome->>launchLocalChrome: waitForWebSocketDebuggerUrl(chrome.port, timeout)
launchLocalChrome-->>V3: { ws, chrome }
deactivate launchLocalChrome
V3->>V3: Create V3Context with WebSocket URL
V3-->>User: Initialized (Chrome listening on port 9222)
deactivate V3
Note over User,ChromeLauncher: External tools can now connect to chrome://inspect on port 9222
|
| <ParamField path="port" type="number" optional> | ||
| When set , the browser will always listen on this port, making it easy to attach external tools or configure |
There was a problem hiding this comment.
There's an extra space after "set" in the description. The text should read "When set, the browser will..." instead of "When set , the browser will...".
| <ParamField path="port" type="number" optional> | |
| When set , the browser will always listen on this port, making it easy to attach external tools or configure | |
| When set, the browser will always listen on this port, making it easy to attach external tools or configure |
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/docs/v3/references/stagehand.mdx
Line: 126:127
Comment:
There's an extra space after "set" in the description. The text should read "When set, the browser will..." instead of "When set , the browser will...".
```suggestion
When set, the browser will always listen on this port, making it easy to attach external tools or configure
```
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
2 issues found across 4 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="packages/core/lib/v3/v3.ts">
<violation number="1" location="packages/core/lib/v3/v3.ts:799">
P2: Local launch uses unvalidated `port`: passing 0/invalid values causes Chrome polling on an unusable port and connection timeouts instead of auto-selecting a port.</violation>
</file>
<file name="packages/docs/v3/references/stagehand.mdx">
<violation number="1" location="packages/docs/v3/references/stagehand.mdx:127">
P3: Extra space after "set" - should be "When set, the browser" instead of "When set , the browser".</violation>
</file>
Since this is your first cubic review, here's how it works:
- cubic automatically reviews your code and comments on bugs and improvements
- Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
- Ask questions if you need clarification on any suggestion
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| const { ws, chrome } = await launchLocalChrome({ | ||
| chromePath: lbo.executablePath, | ||
| chromeFlags, | ||
| port: lbo.port, |
There was a problem hiding this comment.
P2: Local launch uses unvalidated port: passing 0/invalid values causes Chrome polling on an unusable port and connection timeouts instead of auto-selecting a port.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/core/lib/v3/v3.ts, line 799:
<comment>Local launch uses unvalidated `port`: passing 0/invalid values causes Chrome polling on an unusable port and connection timeouts instead of auto-selecting a port.</comment>
<file context>
@@ -796,6 +796,7 @@ export class V3 {
const { ws, chrome } = await launchLocalChrome({
chromePath: lbo.executablePath,
chromeFlags,
+ port: lbo.port,
headless: lbo.headless,
userDataDir,
</file context>
| port: lbo.port, | |
| port: | |
| typeof lbo.port === "number" && | |
| Number.isInteger(lbo.port) && | |
| lbo.port > 0 && | |
| lbo.port <= 65_535 | |
| ? lbo.port | |
| : undefined, |
|
Fixes #1489 |
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
8861ae6
into
browserbase:evals/external-contrib-configure-local-launch-port
why :
In
env: "LOCAL"mode, Stagehand always launches Chrome on a random CDP debugging port. This makes it hard to attach external tools or configurechrome://inspectwith a fixed port.what changed :
port?: numbertoLocalBrowserLaunchOptions.portoption tochrome-launcher.localBrowserLaunchOptions.port.Usage
const stagehand = new Stagehand({
env: "LOCAL",
localBrowserLaunchOptions: {
headless: true,
port: 9222,
},
model: "openai/gpt-4.1-mini",
});
Test plan
pnpm --filter @browserbasehq/stagehand run buildpnpm --filter @browserbasehq/stagehand lint(passes)pnpm --filter @browserbasehq/stagehand test:vitestSummary by cubic
Adds an optional localBrowserLaunchOptions.port to pin the local Chrome CDP debugging port in LOCAL mode. This makes it easy to attach external tools or use chrome://inspect with a fixed port, while keeping the default random port if unset.
Written for commit b27abed. Summary will update on new commits.