Title:
Allow Stagehand to Attach to an Existing Playwright Page for Proper Video Recording
Summary:
When integrating Stagehand with Playwright tests, video recording fails to work as expected. The root cause is that Stagehand’s current initialization (via init() or the deprecated initFromPage()) creates its own browser context and page rather than attaching to the Playwright test runner’s page. Since Playwright’s video recording is configured at the context level (the one that the test runner creates), any actions performed in a separate Stagehand‑created context are not recorded.
What’s Happening:
Proposed Solution:
Modify Stagehand to allow its initialization to accept an existing Playwright page. Specifically:
Impact:
-
For Users:
- Tests will now properly record videos when using Stagehand’s methods, making debugging easier.
- A cleaner integration between Stagehand and the Playwright test runner.
-
For Maintenance:
- Aligns Stagehand’s lifecycle management with Playwright’s, reducing confusion and potential side effects.
- Allows continued use of AI-driven automation without sacrificing the rich artifact collection provided by Playwright.
Next Steps:
- Implement the API change in Stagehand’s initialization code.
- Add tests to ensure that when a page is attached, video recording works as expected.
- Document the new usage pattern for contributors and users.
Title:
Allow Stagehand to Attach to an Existing Playwright Page for Proper Video Recording
Summary:
When integrating Stagehand with Playwright tests, video recording fails to work as expected. The root cause is that Stagehand’s current initialization (via
init()or the deprecatedinitFromPage()) creates its own browser context and page rather than attaching to the Playwright test runner’s page. Since Playwright’s video recording is configured at the context level (the one that the test runner creates), any actions performed in a separate Stagehand‑created context are not recorded.What’s Happening:
Playwright’s Test Runner:
video: "retain-on-failure").Stagehand’s Current Behavior:
init(), Stagehand creates its own browser context and page, independent of the Playwright-managed one.Result:
observe(),act(), etc.) run on a page that isn’t being recorded, causing missing or blank video artifacts.Proposed Solution:
Modify Stagehand to allow its initialization to accept an existing Playwright page. Specifically:
Extend the Initialization API:
init({ page: existingPage })or anattachToPageoption) so that if a Playwright page is provided, Stagehand attaches to that page and its context.Behavior in "Attached" Mode:
contexttoprovidedPage.context().Benefits:
Impact:
For Users:
For Maintenance:
Next Steps: