Skip to content

[STG-1450] Fix Session init failing when no pages are open, falls back to opening about:blank - #1749

Merged
pirate merged 4 commits into
mainfrom
session-init-fixes
Feb 25, 2026
Merged

pirate merged 4 commits into
mainfrom
session-init-fixes

Conversation

@pirate

@pirate pirate commented Feb 24, 2026 •

Copy link
Copy Markdown
Contributor

why

Stagehand API failures were caused on all routes /act, /observe, etc. when session init failed because a page was closed. This adds a fallback to open about:blank so at least the session remains usable instead of just crashing on init.

what changed

test plan


Summary by cubic

Fixes session init when connecting to a browser with zero pages by auto-creating an about:blank tab. Keeps Stagehand routes working after the last page closes and surfaces lint failures via a dedicated cancellation job. Addresses STG-1450.

  • Bug Fixes

    • Replace waitForFirstTopLevelPage with ensureFirstTopLevelPage: check for an existing page, wait with timeout, then create about:blank if none.
    • Simplify errors to a TimeoutError with clearer context; improve logging and add an integration test for zero-page init.
  • CI

    • Run cancellation in a separate job only when lint fails, so failures are visible instead of marked skipped.

Written for commit 45ed6dc. Summary will update on new commits. Review in cubic

Mintlify

0 threads from 0 users in Mintlify

  • No unresolved comments

Open in Mintlify Editor

@changeset-bot

changeset-bot Bot commented Feb 24, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 45ed6dc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@browserbasehq/stagehand Patch
@browserbasehq/stagehand-evals Patch
@browserbasehq/stagehand-server Patch

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

@greptile-apps

greptile-apps Bot commented Feb 24, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Fixed session initialization failures by adding a fallback that creates an about:blank page when no pages are available after connecting to an existing browser session.

  • Added hasTopLevelPage() helper to check if any pages exist
  • Added ensureFirstTopLevelPage() that catches timeout errors and creates a recovery page
  • Replaced waitForFirstTopLevelPage() with ensureFirstTopLevelPage() in the connect flow
  • Added integration test to verify initialization works with zero pages
  • Fixed trailing whitespace in changeset file

Confidence Score: 5/5

  • Safe to merge - robust error handling with proper fallback and test coverage
  • The implementation is clean and defensive: it checks for existing pages first, only catches the specific timeout error, and provides proper logging. The fallback creates about:blank which is a safe default. The test coverage validates the fix works correctly.
  • No files require special attention

Important Files Changed

Filename Overview
packages/core/lib/v3/understudy/context.ts Added fallback logic to create about:blank page when session init detects no pages, preventing session crashes
packages/core/tests/integration/connect-to-existing-browser.spec.ts Added test to verify session initialization succeeds when connecting to browser with zero pages

Last reviewed commit: 254ae6e

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

cubic-dev-ai[bot]

This comment was marked as resolved.

@pirate pirate changed the title Fix Session init failing when no pages are open, falls back to opening about:blank [STG-1450] Fix Session init failing when no pages are open, falls back to opening about:blank Feb 24, 2026
@pirate
pirate force-pushed the session-init-fixes branch from c75ce07 to f71b43b Compare February 24, 2026 23:29
@pirate
pirate force-pushed the session-init-fixes branch from f71b43b to 8950c76 Compare February 24, 2026 23:30
@pirate
pirate merged commit 7390508 into main Feb 25, 2026
169 checks passed
miguelg719 pushed a commit that referenced this pull request Mar 18, 2026
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/[email protected]

### Minor Changes

- [#1816](#1816)
[`687d54a`](687d54a)
Thanks [@shrey150](https://github.com/shrey150)! - Add `--context-id`
and `--persist` flags to `browse open` for loading and persisting
Browserbase Contexts across sessions

- [#1793](#1793)
[`e38c13b`](e38c13b)
Thanks [@shrey150](https://github.com/shrey150)! - Initial release of
browse CLI - browser automation for AI agents

### Patch Changes

- [#1806](#1806)
[`f8c7738`](f8c7738)
Thanks [@shrey150](https://github.com/shrey150)! - Fix `browse env`
showing stale mode after `browse env remote`

- Updated dependencies
\[[`505e8c6`](505e8c6),
[`2f43ffa`](2f43ffa),
[`63ee247`](63ee247),
[`7dc35f5`](7dc35f5),
[`335cf47`](335cf47),
[`6ba0a1d`](6ba0a1d),
[`4ff3bb8`](4ff3bb8),
[`c27054b`](c27054b),
[`2abf5b9`](2abf5b9),
[`7817fcc`](7817fcc),
[`7390508`](7390508),
[`611f43a`](611f43a),
[`521a10e`](521a10e),
[`2402a3c`](2402a3c)]:
    -   @browserbasehq/[email protected]

## @browserbasehq/[email protected]

### Minor Changes

- [#1779](#1779)
[`2f43ffa`](2f43ffa)
Thanks [@shrey150](https://github.com/shrey150)! - feat: add
`cdpHeaders` option to `localBrowserLaunchOptions` for passing custom
HTTP headers when connecting to an existing browser via CDP URL

- [#1834](#1834)
[`63ee247`](63ee247)
Thanks [@tkattkat](https://github.com/tkattkat)! - Update stagehand
agents search tool

- [#1774](#1774)
[`521a10e`](521a10e)
Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - add new
page.setExtraHTTPHeaders() method

### Patch Changes

- [#1759](#1759)
[`505e8c6`](505e8c6)
Thanks [@shrey150](https://github.com/shrey150)! - Add bedrock to the
provider enum in model configuration schemas and regenerate OpenAPI
spec.

- [#1814](#1814)
[`7dc35f5`](7dc35f5)
Thanks [@tkattkat](https://github.com/tkattkat)! - Change usage of
openai provider in agent to default to store:false

- [#1846](#1846)
[`335cf47`](335cf47)
Thanks [@aq17](https://github.com/aq17)! - Fix streaming finished event
being silently dropped. The final SSE event containing the result
payload (success status, message, actions, usage, and messages) was
previously discarded instead of being yielded to the caller.

- [#1764](#1764)
[`6ba0a1d`](6ba0a1d)
Thanks [@shrey150](https://github.com/shrey150)! - Expose `headers` in
`GoogleVertexProviderSettings` so model configs can pass custom provider
headers (for example `X-Goog-Priority`) without TypeScript errors.

- [#1847](#1847)
[`4ff3bb8`](4ff3bb8)
Thanks [@miguelg719](https://github.com/miguelg719)! - Enable FlowLogger
on BROWSERBASE_FLOW_LOGS=1

- [#1752](#1752)
[`c27054b`](c27054b)
Thanks [@derekmeegan](https://github.com/derekmeegan)! - fix: pause
Browserbase agents while captcha solving is active and improve CUA
recovery after the solve completes

- [#1800](#1800)
[`2abf5b9`](2abf5b9)
Thanks [@shrey150](https://github.com/shrey150)! - Make projectId
optional for Browserbase sessions — only BROWSERBASE_API_KEY is required

- [#1766](#1766)
[`7817fcc`](7817fcc)
Thanks [@tkattkat](https://github.com/tkattkat)! - Add configurable
timeout to tools in agent

- [#1749](#1749)
[`7390508`](7390508)
Thanks [@pirate](https://github.com/pirate)! - When connecting to a
browser session that has zero open tabs, Stagehand now automatically
creates an initial `about:blank` tab so the connection can continue.

- [#1761](#1761)
[`611f43a`](611f43a)
Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - fix issue
where handlePossibleNavigation was producing unnecessary error logs on
clicks that trigger page close

- [#1817](#1817)
[`2402a3c`](2402a3c)
Thanks [@tkattkat](https://github.com/tkattkat)! - Add support for
passing custom headers in clientOptions

## @browserbasehq/[email protected]

### Patch Changes

- Updated dependencies
\[[`505e8c6`](505e8c6),
[`2f43ffa`](2f43ffa),
[`63ee247`](63ee247),
[`7dc35f5`](7dc35f5),
[`335cf47`](335cf47),
[`6ba0a1d`](6ba0a1d),
[`4ff3bb8`](4ff3bb8),
[`c27054b`](c27054b),
[`2abf5b9`](2abf5b9),
[`7817fcc`](7817fcc),
[`7390508`](7390508),
[`611f43a`](611f43a),
[`521a10e`](521a10e),
[`2402a3c`](2402a3c)]:
    -   @browserbasehq/[email protected]

## @browserbasehq/[email protected]

### Patch Changes

- [#1759](#1759)
[`505e8c6`](505e8c6)
Thanks [@shrey150](https://github.com/shrey150)! - Add bedrock to the
provider enum in model configuration schemas and regenerate OpenAPI
spec.

- Updated dependencies
\[[`505e8c6`](505e8c6),
[`2f43ffa`](2f43ffa),
[`63ee247`](63ee247),
[`7dc35f5`](7dc35f5),
[`335cf47`](335cf47),
[`6ba0a1d`](6ba0a1d),
[`4ff3bb8`](4ff3bb8),
[`c27054b`](c27054b),
[`2abf5b9`](2abf5b9),
[`7817fcc`](7817fcc),
[`7390508`](7390508),
[`611f43a`](611f43a),
[`521a10e`](521a10e),
[`2402a3c`](2402a3c)]:
    -   @browserbasehq/[email protected]

## @browserbasehq/[email protected]

### Patch Changes

- Updated dependencies
\[[`505e8c6`](505e8c6),
[`2f43ffa`](2f43ffa),
[`63ee247`](63ee247),
[`7dc35f5`](7dc35f5),
[`335cf47`](335cf47),
[`6ba0a1d`](6ba0a1d),
[`4ff3bb8`](4ff3bb8),
[`c27054b`](c27054b),
[`2abf5b9`](2abf5b9),
[`7817fcc`](7817fcc),
[`7390508`](7390508),
[`611f43a`](611f43a),
[`521a10e`](521a10e),
[`2402a3c`](2402a3c)]:
    -   @browserbasehq/[email protected]

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
felipeofdev-ai pushed a commit to felipeofdev-ai/stagehand that referenced this pull request Aug 4, 2026
…k to opening about:blank (browserbase#1749)

# why

Stagehand API failures were caused on all routes `/act`, `/observe`,
etc. when session init failed because a page was closed. This adds a
fallback to open about:blank so at least the session remains usable
instead of just crashing on init.

# what changed

# test plan

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Fixes session init when connecting to a browser with zero pages by
auto-creating an about:blank tab. Keeps Stagehand routes working after
the last page closes and surfaces lint failures via a dedicated
cancellation job. Addresses STG-1450.

- **Bug Fixes**
- Replace waitForFirstTopLevelPage with ensureFirstTopLevelPage: check
for an existing page, wait with timeout, then create about:blank if
none.
- Simplify errors to a TimeoutError with clearer context; improve
logging and add an integration test for zero-page init.

- **CI**
- Run cancellation in a separate job only when lint fails, so failures
are visible instead of marked skipped.

<sup>Written for commit 45ed6dc.
Summary will update on new commits. <a
href="https://cubic.dev/pr/browserbase/stagehand/pull/1749">Review in
cubic</a></sup>

<!-- End of auto-generated description by cubic. -->

<!-- mintlify-editor-comments:start -->
Mintlify
---
0 threads from 0 users in Mintlify

- No unresolved comments
<!-- mintlify-editor-comments:end -->

<!-- mintlify-comment-->

<a
href="https://dashboard.mintlify.com/browserbase/stagehand/editor/session-init-fixes?source=pr_comment"
target="_blank" rel="noopener noreferrer"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://d3gk2c5xim1je2.cloudfront.net/assets/open-mintlify-editor-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://d3gk2c5xim1je2.cloudfront.net/assets/open-mintlify-editor-light.svg"><img
src="https://d3gk2c5xim1je2.cloudfront.net/assets/open-mintlify-editor-light.svg"
alt="Open in Mintlify Editor"></picture></a>

<!-- /mintlify-comment -->
felipeofdev-ai pushed a commit to felipeofdev-ai/stagehand that referenced this pull request Aug 4, 2026
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/[email protected]

### Minor Changes

- [browserbase#1816](browserbase#1816)
[`687d54a`](browserbase@687d54a)
Thanks [@shrey150](https://github.com/shrey150)! - Add `--context-id`
and `--persist` flags to `browse open` for loading and persisting
Browserbase Contexts across sessions

- [browserbase#1793](browserbase#1793)
[`e38c13b`](browserbase@e38c13b)
Thanks [@shrey150](https://github.com/shrey150)! - Initial release of
browse CLI - browser automation for AI agents

### Patch Changes

- [browserbase#1806](browserbase#1806)
[`f8c7738`](browserbase@f8c7738)
Thanks [@shrey150](https://github.com/shrey150)! - Fix `browse env`
showing stale mode after `browse env remote`

- Updated dependencies
\[[`505e8c6`](browserbase@505e8c6),
[`2f43ffa`](browserbase@2f43ffa),
[`63ee247`](browserbase@63ee247),
[`7dc35f5`](browserbase@7dc35f5),
[`335cf47`](browserbase@335cf47),
[`6ba0a1d`](browserbase@6ba0a1d),
[`4ff3bb8`](browserbase@4ff3bb8),
[`c27054b`](browserbase@c27054b),
[`2abf5b9`](browserbase@2abf5b9),
[`7817fcc`](browserbase@7817fcc),
[`7390508`](browserbase@7390508),
[`611f43a`](browserbase@611f43a),
[`521a10e`](browserbase@521a10e),
[`2402a3c`](browserbase@2402a3c)]:
    -   @browserbasehq/[email protected]

## @browserbasehq/[email protected]

### Minor Changes

- [browserbase#1779](browserbase#1779)
[`2f43ffa`](browserbase@2f43ffa)
Thanks [@shrey150](https://github.com/shrey150)! - feat: add
`cdpHeaders` option to `localBrowserLaunchOptions` for passing custom
HTTP headers when connecting to an existing browser via CDP URL

- [browserbase#1834](browserbase#1834)
[`63ee247`](browserbase@63ee247)
Thanks [@tkattkat](https://github.com/tkattkat)! - Update stagehand
agents search tool

- [browserbase#1774](browserbase#1774)
[`521a10e`](browserbase@521a10e)
Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - add new
page.setExtraHTTPHeaders() method

### Patch Changes

- [browserbase#1759](browserbase#1759)
[`505e8c6`](browserbase@505e8c6)
Thanks [@shrey150](https://github.com/shrey150)! - Add bedrock to the
provider enum in model configuration schemas and regenerate OpenAPI
spec.

- [browserbase#1814](browserbase#1814)
[`7dc35f5`](browserbase@7dc35f5)
Thanks [@tkattkat](https://github.com/tkattkat)! - Change usage of
openai provider in agent to default to store:false

- [browserbase#1846](browserbase#1846)
[`335cf47`](browserbase@335cf47)
Thanks [@aq17](https://github.com/aq17)! - Fix streaming finished event
being silently dropped. The final SSE event containing the result
payload (success status, message, actions, usage, and messages) was
previously discarded instead of being yielded to the caller.

- [browserbase#1764](browserbase#1764)
[`6ba0a1d`](browserbase@6ba0a1d)
Thanks [@shrey150](https://github.com/shrey150)! - Expose `headers` in
`GoogleVertexProviderSettings` so model configs can pass custom provider
headers (for example `X-Goog-Priority`) without TypeScript errors.

- [browserbase#1847](browserbase#1847)
[`4ff3bb8`](browserbase@4ff3bb8)
Thanks [@miguelg719](https://github.com/miguelg719)! - Enable FlowLogger
on BROWSERBASE_FLOW_LOGS=1

- [browserbase#1752](browserbase#1752)
[`c27054b`](browserbase@c27054b)
Thanks [@derekmeegan](https://github.com/derekmeegan)! - fix: pause
Browserbase agents while captcha solving is active and improve CUA
recovery after the solve completes

- [browserbase#1800](browserbase#1800)
[`2abf5b9`](browserbase@2abf5b9)
Thanks [@shrey150](https://github.com/shrey150)! - Make projectId
optional for Browserbase sessions — only BROWSERBASE_API_KEY is required

- [browserbase#1766](browserbase#1766)
[`7817fcc`](browserbase@7817fcc)
Thanks [@tkattkat](https://github.com/tkattkat)! - Add configurable
timeout to tools in agent

- [browserbase#1749](browserbase#1749)
[`7390508`](browserbase@7390508)
Thanks [@pirate](https://github.com/pirate)! - When connecting to a
browser session that has zero open tabs, Stagehand now automatically
creates an initial `about:blank` tab so the connection can continue.

- [browserbase#1761](browserbase#1761)
[`611f43a`](browserbase@611f43a)
Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - fix issue
where handlePossibleNavigation was producing unnecessary error logs on
clicks that trigger page close

- [browserbase#1817](browserbase#1817)
[`2402a3c`](browserbase@2402a3c)
Thanks [@tkattkat](https://github.com/tkattkat)! - Add support for
passing custom headers in clientOptions

## @browserbasehq/[email protected]

### Patch Changes

- Updated dependencies
\[[`505e8c6`](browserbase@505e8c6),
[`2f43ffa`](browserbase@2f43ffa),
[`63ee247`](browserbase@63ee247),
[`7dc35f5`](browserbase@7dc35f5),
[`335cf47`](browserbase@335cf47),
[`6ba0a1d`](browserbase@6ba0a1d),
[`4ff3bb8`](browserbase@4ff3bb8),
[`c27054b`](browserbase@c27054b),
[`2abf5b9`](browserbase@2abf5b9),
[`7817fcc`](browserbase@7817fcc),
[`7390508`](browserbase@7390508),
[`611f43a`](browserbase@611f43a),
[`521a10e`](browserbase@521a10e),
[`2402a3c`](browserbase@2402a3c)]:
    -   @browserbasehq/[email protected]

## @browserbasehq/[email protected]

### Patch Changes

- [browserbase#1759](browserbase#1759)
[`505e8c6`](browserbase@505e8c6)
Thanks [@shrey150](https://github.com/shrey150)! - Add bedrock to the
provider enum in model configuration schemas and regenerate OpenAPI
spec.

- Updated dependencies
\[[`505e8c6`](browserbase@505e8c6),
[`2f43ffa`](browserbase@2f43ffa),
[`63ee247`](browserbase@63ee247),
[`7dc35f5`](browserbase@7dc35f5),
[`335cf47`](browserbase@335cf47),
[`6ba0a1d`](browserbase@6ba0a1d),
[`4ff3bb8`](browserbase@4ff3bb8),
[`c27054b`](browserbase@c27054b),
[`2abf5b9`](browserbase@2abf5b9),
[`7817fcc`](browserbase@7817fcc),
[`7390508`](browserbase@7390508),
[`611f43a`](browserbase@611f43a),
[`521a10e`](browserbase@521a10e),
[`2402a3c`](browserbase@2402a3c)]:
    -   @browserbasehq/[email protected]

## @browserbasehq/[email protected]

### Patch Changes

- Updated dependencies
\[[`505e8c6`](browserbase@505e8c6),
[`2f43ffa`](browserbase@2f43ffa),
[`63ee247`](browserbase@63ee247),
[`7dc35f5`](browserbase@7dc35f5),
[`335cf47`](browserbase@335cf47),
[`6ba0a1d`](browserbase@6ba0a1d),
[`4ff3bb8`](browserbase@4ff3bb8),
[`c27054b`](browserbase@c27054b),
[`2abf5b9`](browserbase@2abf5b9),
[`7817fcc`](browserbase@7817fcc),
[`7390508`](browserbase@7390508),
[`611f43a`](browserbase@611f43a),
[`521a10e`](browserbase@521a10e),
[`2402a3c`](browserbase@2402a3c)]:
    -   @browserbasehq/[email protected]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants