Pass local launch options when attaching over CDP#2146
Conversation
🦋 Changeset detectedLatest commit: 9b8bb88 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 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 |
|
bugbot run |
|
Skipping Bugbot: Bugbot is disabled for this repository. Visit the Bugbot dashboard to update your settings. |
66252b2 to
9b8bb88
Compare
There was a problem hiding this comment.
No issues found across 3 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Architecture diagram
sequenceDiagram
participant Client as Client Code
participant V3 as V3 Class
participant Context as V3Context
participant Page as Page
Note over Client,Page: LOCAL CDP Attach Path (New Flow)
Client->>V3: new V3({ localBrowserLaunchOptions })
V3->>V3: init()
alt env === "LOCAL" with cdpUrl
V3->>V3: Determine attach mode via cdpUrl
Note over V3,Context: NEW: Forward full localBrowserLaunchOptions
V3->>Context: V3Context.create(cdpUrl, {<br/> env: "LOCAL",<br/> cdpHeaders: lbo.cdpHeaders,<br/> localBrowserLaunchOptions: lbo<br/>})
Context->>Context: Create CDP connection
Context-->>V3: ctx instance
V3->>Context: ctx.conn.onTransportClosed(callback)
Note over Context,Page: Viewport/DSF applied via launchOptions
Context->>Page: Page.applyLaunchOptions({<br/> viewport,<br/> deviceScaleFactor<br/>})
Page-->>Context: Page configured
Context-->>V3: Ready for use
V3-->>Client: Instance ready
end
alt env === "LOCAL" without cdpUrl (Launch Path - unchanged)
Note over V3,Context: Existing launch path (not changed)
V3->>Context: V3Context.create(env, launchOptions)
Context-->>V3: ctx instance
end
pirate
left a comment
There was a problem hiding this comment.
This starts to drift from the naming of localBrowserLaunchOptions, it's a bit of a slippery slope, but it's fine for now.
In the future we should probably split stuff like viewport settings out into a separate browser_options or something to indicate it's applied to all browsers we connect to, not only browsers we launch.
Summary
localBrowserLaunchOptionsintoV3Context.create()when LOCAL mode attaches to an existing browser viacdpUrl.Why
The launch path already passes local browser options into
V3Context, which letsPage.create()apply the configured viewport anddeviceScaleFactor. The CDP attach path only forwardedenvandcdpHeaders, so attached local sessions skipped that Page-level viewport setup.E2E Test Matrix
pnpm install --frozen-lockfileDone in 13.9s.pnpm exec turbo run build:esm --filter=@browserbasehq/stagehandgen-version,build-dom-scripts, andbuild:esm; output ended withTasks: 3 successful, 3 total.pnpm --filter @browserbasehq/stagehand exec vitest run --config vitest.esm.config.mjs dist/esm/tests/unit/browserbase-session-accessors.test.jsTest Files 1 passed (1),Tests 6 passed (6).node --input-type=module <inline LOCAL CDP attach viewport smoke>cdpUrlwithviewport: { width: 1440, height: 900 }, and printed{"status":"pass","cdpAttachViewport":{"innerWidth":1440,"innerHeight":900,"devicePixelRatio":1,"bottomRightHit":"target"}}.pnpm exec changeset status --since=origin/main@browserbasehq/stagehandand dependent workspace packages.