Skip to content

feat: attach to playwright #923

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

4t145
Copy link

@4t145 4t145 commented Jul 28, 2025

why

To solve #507

what changed

Add a parameter to constructor of Stagehand, which allow pass a playwright context into it and attach playwright on it.

test plan

Tested in personal project.

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.

Greptile Summary

This PR adds the ability to attach Stagehand to an existing Playwright browser context instead of creating its own. The change introduces a new optional attachToLocalBrowser parameter to the Stagehand constructor that accepts a Playwright BrowserContext. When provided, Stagehand will use this existing context rather than creating a new one.

The implementation modifies the getBrowser function to check for the attachToLocalBrowser parameter and return early with the provided context when available. This bypasses the normal browser creation flow and ensures all Stagehand operations occur within the same context that was passed in.

This change addresses issue #507 where video recording wasn't working in e2e tests. The root cause was that Playwright's video recording is configured at the context level, but Stagehand was creating its own separate context, so actions weren't being captured. By allowing attachment to an existing context, video recording and other Playwright artifacts are preserved.

The change is backward compatible since the parameter is optional, and it integrates cleanly with the existing browser initialization logic in the codebase.

Confidence score: 4/5

  • This PR is safe to merge with minimal risk of issues
  • The implementation is clean and follows existing patterns, with proper logging and error handling
  • No files need additional attention - the changes are straightforward and well-contained

2 files reviewed, 1 comment

Edit Code Review Bot Settings | Greptile

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Copy link

changeset-bot bot commented Jul 28, 2025

⚠️ No Changeset found

Latest commit: 9e3c8b0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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.

1 participant