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 intomainfrom
session-init-fixes
Feb 25, 2026
Merged

[STG-1450] Fix Session init failing when no pages are open, falls back to opening about:blank#1749
pirate merged 4 commits intomainfrom
session-init-fixes

Conversation

@pirate
Copy link
Member

@pirate pirate commented Feb 24, 2026

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
Copy link

changeset-bot bot commented Feb 24, 2026

🦋 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
Copy link
Contributor

greptile-apps bot commented Feb 24, 2026

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

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

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
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