-
Notifications
You must be signed in to change notification settings - Fork 1.2k
set default viewport when running on browserbase #1114
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
Conversation
🦋 Changeset detectedLatest commit: 97ccc5e The changes in this PR will be included in the next version bump. 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.
Greptile Overview
Summary
This PR introduces a default viewport setting for Browserbase sessions to ensure consistent browser dimensions across all sessions. The change addresses an inconsistency where default viewport settings (1288x711) were only defined in the exported `StagehandConfig` but weren't actually applied when creating Browserbase sessions through the SDK.The implementation creates a new utility module browserbaseDefaults.ts that exports a DEFAULT_BROWSERBASE_VIEWPORT constant and an applyDefaultBrowserSettingsViewport function. This function merges user-provided session parameters with default viewport settings, ensuring that every Browserbase session has consistent dimensions unless explicitly overridden.
The changes are applied in two key locations:
- Session Creation (
lib/index.ts): Both in thegetBrowser()method when creating new sessions and in the constructor when storing session parameters - API Layer (
lib/api.ts): When preparing session creation parameters for the Browserbase API
This approach maintains backward compatibility while ensuring that all Browserbase sessions have predictable viewport behavior, which is crucial for web automation reliability and consistent screenshot/interaction behavior.
Important Files Changed
Changed Files
| Filename | Score | Overview |
|---|---|---|
| lib/browserbaseDefaults.ts | 5/5 | New utility file that defines default viewport constants and helper function for applying defaults |
| lib/index.ts | 4/5 | Applies default viewport settings during session creation and constructor initialization |
| lib/api.ts | 5/5 | Ensures default viewport is applied when creating sessions through the API layer |
Confidence score: 5/5
- This PR is safe to merge with minimal risk as it only adds default values and doesn't change existing behavior when users provide explicit viewport settings
- Score reflects well-structured implementation with proper separation of concerns and consistent application across the codebase
- No files require special attention as the changes are straightforward and follow good software engineering practices
Sequence Diagram
sequenceDiagram
participant User
participant Stagehand
participant StagehandAPI
participant browserbaseDefaults
participant getBrowser
participant Browserbase
User->>Stagehand: "new Stagehand(constructorParams)"
Stagehand->>browserbaseDefaults: "applyDefaultBrowserSettingsViewport(browserbaseSessionCreateParams)"
browserbaseDefaults-->>Stagehand: "params with default viewport (1288x711)"
User->>Stagehand: "init()"
alt usingAPI is true
Stagehand->>StagehandAPI: "new StagehandAPI({apiKey, projectId, logger})"
Stagehand->>StagehandAPI: "init({modelName, browserbaseSessionCreateParams, ...})"
StagehandAPI->>browserbaseDefaults: "applyDefaultBrowserSettingsViewport(browserbaseSessionCreateParams)"
browserbaseDefaults-->>StagehandAPI: "sessionCreateParams with default viewport"
StagehandAPI->>Browserbase: "POST /sessions/start with sessionCreateParams"
Browserbase-->>StagehandAPI: "session response"
StagehandAPI-->>Stagehand: "{sessionId, available}"
end
Stagehand->>getBrowser: "getBrowser(apiKey, projectId, env, ...browserbaseSessionCreateParams)"
alt env === "BROWSERBASE"
getBrowser->>browserbaseDefaults: "applyDefaultBrowserSettingsViewport(browserbaseSessionCreateParams)"
browserbaseDefaults-->>getBrowser: "sessionCreateParams with default viewport (1288x711)"
getBrowser->>Browserbase: "sessions.create({projectId, ...sessionCreateParams})"
Browserbase-->>getBrowser: "session with connectUrl"
getBrowser->>Browserbase: "chromium.connectOverCDP(connectUrl)"
Browserbase-->>getBrowser: "browser context"
else env === "LOCAL"
getBrowser->>getBrowser: "chromium.launchPersistentContext with viewport (1288x711)"
end
getBrowser-->>Stagehand: "{browser, context, debugUrl, sessionUrl, sessionId}"
Stagehand-->>User: "{debugUrl, sessionUrl, sessionId}"
3 files reviewed, no comments
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@2.5.2 ### Patch Changes - [#1114](#1114) [`c0fbc51`](c0fbc51) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - configure default viewport when running on browserbase ## @browserbasehq/stagehand-evals@1.1.1 ### Patch Changes - Updated dependencies \[[`c0fbc51`](c0fbc51)]: - @browserbasehq/stagehand@2.5.2 ## @browserbasehq/stagehand-examples@1.0.11 ### Patch Changes - Updated dependencies \[[`c0fbc51`](c0fbc51)]: - @browserbasehq/stagehand@2.5.2 Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
why
StagehandConfigwhat changed
test plan