-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Description
Problem
When using Stagehand V3 in LOCAL mode, the Chrome DevTools Protocol (CDP) debugging port is randomly assigned each time the browser launches. This makes it impossible to:
- Connect external debugging tools to a fixed port
- Configure
chrome://inspectwith a persistent port - Set up development workflows that rely on a known port
Current Behavior
- Passing
--remote-debugging-port=9222inlocalBrowserLaunchOptions.argsis ignored because Stagehand internally callsgetRandomPort()and adds its own--remote-debugging-port=${randomPort}flag - The only workaround is to launch Chrome manually and use
cdpUrlto connect
Expected Behavior
Allow users to specify a fixed debugging port via localBrowserLaunchOptions.port:
const stagehand = new Stagehand({
env: "LOCAL",
localBrowserLaunchOptions: {
headless: true,
port: 9222, // <-- New option to pin the debugging port
},
model: "openai/gpt-4o",
});Technical Details
Looking at the source code in dist/index.js:
-
Line 35781:
requestedPortdefaults to 0this.requestedPort = defaults(this.opts.port, 0);
-
Line 35909: If
requestedPort === 0, a random port is assignedthis.port = yield getRandomPort();
-
Line 64707: User
argsare added, but Stagehand's random port takes precedenceif (Array.isArray(lbo.args)) chromeFlags.push(...lbo.args);
The internal port option exists but is not exposed through LocalBrowserLaunchOptions.
Proposed Solution
Add port to the LocalBrowserLaunchOptions interface and pass it through to the Chrome launcher:
interface LocalBrowserLaunchOptions {
// ... existing options
port?: number; // Fixed CDP debugging port
}Environment
- Stagehand version: 3.0.6
- OS: macOS
Metadata
Metadata
Assignees
Labels
No labels