-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[feat]: add configurable local CDP debugging port #1575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feat]: add configurable local CDP debugging port #1575
Conversation
# why :
In `env: "LOCAL"` mode, Stagehand always launches Chrome on a random CDP
debugging port. This makes it hard to attach external tools or configure
`chrome://inspect` with a fixed port.
# what changed :
- Add an optional `port?: number` to `LocalBrowserLaunchOptions`.
- Thread this value through to the local Chrome launcher and pass it as
the `port` option to `chrome-launcher`.
- Update V3 docs to document `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 build`
- `pnpm --filter @browserbasehq/stagehand lint` (passes)
- `pnpm --filter @browserbasehq/stagehand test:vitest`
<!-- This is an auto-generated description by cubic. -->
---
## Summary 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.
- **New Features**
- Added port?: number to LocalBrowserLaunchOptions and passed it through
launchLocalChrome to chrome-launcher.
- Updated docs to describe localBrowserLaunchOptions.port and its usage.
<sup>Written for commit b27abed.
Summary will update on new commits.</sup>
<!-- End of auto-generated description by cubic. -->
---------
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
🦋 Changeset detectedLatest commit: d7d2233 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No issues found across 4 files
Greptile SummaryThis PR adds an optional Key Changes:
The implementation is clean and follows the existing pattern for optional configuration parameters. The change is backward compatible (defaults to random port when unspecified) and properly validated by the Zod schema. Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant Stagehand
participant V3
participant launchLocalChrome
participant ChromeLauncher
User->>Stagehand: new Stagehand({ env: "LOCAL", localBrowserLaunchOptions: { port: 9222 } })
User->>Stagehand: init()
Stagehand->>V3: constructor with options
V3->>V3: Extract localBrowserLaunchOptions.port
V3->>launchLocalChrome: launchLocalChrome({ port: 9222, ... })
launchLocalChrome->>ChromeLauncher: launch({ port: 9222, ... })
ChromeLauncher-->>launchLocalChrome: chrome instance with fixed port
launchLocalChrome->>launchLocalChrome: waitForWebSocketDebuggerUrl(chrome.port)
launchLocalChrome-->>V3: { ws, chrome }
V3-->>Stagehand: initialized
Note over User,ChromeLauncher: Chrome now listens on port 9222 for debugging
|
Add documentation for the `port` option in `LocalBrowserLaunchOptions` that was added in PR browserbase#1575. This option allows users to specify a fixed Chrome CDP debugging port instead of using a randomly assigned port. Updated: - packages/docs/v3/references/stagehand.mdx - Added port parameter to LocalBrowserLaunchOptions documentation - packages/docs/v3/configuration/browser.mdx - Added port to example and new "Fixed CDP Debugging Port" section explaining the feature Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## @browserbasehq/stagehand@3.0.8 ### Patch Changes - [#1514](#1514) [`40ce5cc`](40ce5cc) Thanks [@tkattkat](https://github.com/tkattkat)! - Rename the close tool in agent to "done" - [#1574](#1574) [`5506f41`](5506f41) Thanks [@tkattkat](https://github.com/tkattkat)! - fix(server): pass cdpUrl to localBrowserLaunchOptions when launchOptions absent - [#1521](#1521) [`84c05ca`](84c05ca) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - fix: get agent cache working in API mode - [#1486](#1486) [`692ffa0`](692ffa0) Thanks [@tkattkat](https://github.com/tkattkat)! - improve logging in agent - [#1551](#1551) [`1ef8901`](1ef8901) Thanks [@miguelg719](https://github.com/miguelg719)! - move extract handler response log to after URL injection - [#1495](#1495) [`72ac775`](72ac775) Thanks [@tkattkat](https://github.com/tkattkat)! - export tool function & type to simplify defining custom tools - [#1481](#1481) [`3d5af07`](3d5af07) Thanks [@tkattkat](https://github.com/tkattkat)! - add waitForTimeout to page - [#1423](#1423) [`40e1d80`](40e1d80) Thanks [@miguelg719](https://github.com/miguelg719)! - Improve benchmark handling and add metadata - [#1588](#1588) [`56c0d24`](56c0d24) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - add SnapshotOptions to page.snapshot() - [#1483](#1483) [`16d72fb`](16d72fb) Thanks [@tkattkat](https://github.com/tkattkat)! - Optimize screenshot handling in agent hybrid mode - [#1498](#1498) [`088c4cc`](088c4cc) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - fix: replaying cached actions (for agent & act) now uses the originally defined model, (instead of default model) when action fails and rerunning inference is needed - [#1575](#1575) [`4276f4a`](4276f4a) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - expose port param in localBrowserLaunchOptions - [#1544](#1544) [`6005786`](6005786) Thanks [@tkattkat](https://github.com/tkattkat)! - Recommend hybrid mode over DOM mode in agent, which is now considered legacy - [#1505](#1505) [`6fbf5fc`](6fbf5fc) Thanks [@tkattkat](https://github.com/tkattkat)! - Add structured output to agent result + ensure close tool is always called - [#1511](#1511) [`704cf18`](704cf18) Thanks [@shrey150](https://github.com/shrey150)! - Fix ControlOrMeta keypress event - [#1480](#1480) [`091296e`](091296e) Thanks [@tkattkat](https://github.com/tkattkat)! - Update agent to only calculate xpath when caching is enabled - [#1509](#1509) [`e56c6eb`](e56c6eb) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - add support for page.waitForSelector() - [#1478](#1478) [`2cb78d0`](2cb78d0) Thanks [@tkattkat](https://github.com/tkattkat)! - update agent message handling - [#1518](#1518) [`5dad639`](5dad639) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - add page.snapshot() for capturing a stringified DOM snapshot of the page, including an xpath map & url map - [#1576](#1576) [`b7c2571`](b7c2571) Thanks [@tkattkat](https://github.com/tkattkat)! - utilize waitForSelector when running agent cache - [#1560](#1560) [`4c69117`](4c69117) Thanks [@tkattkat](https://github.com/tkattkat)! - Update coordinate handling in cua and hybrid ## @browserbasehq/stagehand-server@3.5.0 ### Minor Changes - [#1578](#1578) [`a5074bd`](a5074bd) Thanks [@monadoid](https://github.com/monadoid)! - /end endpoint no longer takes an empty object - instead, no request body is required. ### Patch Changes - Updated dependencies \[[`40ce5cc`](40ce5cc), [`5506f41`](5506f41), [`84c05ca`](84c05ca), [`692ffa0`](692ffa0), [`1ef8901`](1ef8901), [`72ac775`](72ac775), [`3d5af07`](3d5af07), [`40e1d80`](40e1d80), [`56c0d24`](56c0d24), [`16d72fb`](16d72fb), [`088c4cc`](088c4cc), [`4276f4a`](4276f4a), [`6005786`](6005786), [`6fbf5fc`](6fbf5fc), [`704cf18`](704cf18), [`091296e`](091296e), [`e56c6eb`](e56c6eb), [`2cb78d0`](2cb78d0), [`5dad639`](5dad639), [`b7c2571`](b7c2571), [`4c69117`](4c69117)]: - @browserbasehq/stagehand@3.0.8 ## @browserbasehq/stagehand-evals@1.1.7 ### Patch Changes - Updated dependencies \[[`40ce5cc`](40ce5cc), [`5506f41`](5506f41), [`84c05ca`](84c05ca), [`692ffa0`](692ffa0), [`1ef8901`](1ef8901), [`72ac775`](72ac775), [`3d5af07`](3d5af07), [`40e1d80`](40e1d80), [`56c0d24`](56c0d24), [`16d72fb`](16d72fb), [`088c4cc`](088c4cc), [`4276f4a`](4276f4a), [`6005786`](6005786), [`6fbf5fc`](6fbf5fc), [`704cf18`](704cf18), [`091296e`](091296e), [`e56c6eb`](e56c6eb), [`2cb78d0`](2cb78d0), [`5dad639`](5dad639), [`b7c2571`](b7c2571), [`4c69117`](4c69117)]: - @browserbasehq/stagehand@3.0.8 Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
this PR was opened on behalf of @dhanushchalicheemala. thanks for the contribution!!
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 d7d2233. Summary will update on new commits.
why
what changed
test plan