Fix: Ensure goto Uses Overridden Page in act/performPlaywrightMethod for Proper DOM Injection #453
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why
fixes #443
The current implementation of the
"goto"
command within theact
handler callspage.goto
on the original page instance. This prevents Stagehand’s DOM scripts from being injected as intended. This PR addresses the issue by explicitly handling"goto"
commands to use the overridden page instance, ensuring that the DOM modifications occur correctly.What Changed
Dedicated Branch for
"goto"
Command:Added a specific branch in the
_performPlaywrightMethod
method to handle the"goto"
command. The URL is extracted from the command arguments and passed directly tothis.stagehandPage.page.goto(url)
, ensuring that the overridden page (with the injected DOM scripts) is used.Enhanced Logging and Error Handling:
Introduced additional logging for the
"goto"
command execution to improve debugging and traceability. Error handling has been updated to catch and log exceptions appropriately during navigation.DOM Settling After Navigation:
After navigation, the method waits for the DOM to settle using
_waitForSettledDom
, guaranteeing that the page is fully loaded and the Stagehand scripts have been injected.Test Plan
Basic Navigation Test:
"goto https://example.com"
via Stagehand.Error Handling:
PlaywrightCommandException
is thrown.Regression Test for Other Methods:
"click"
,"fill"
,"press"
) to ensure their functionality remains unchanged.End-to-End Flow: