Conversation
The wait is a single Runtime.evaluate pinned to the execution context that was current when it was issued, typically the document a click is about to navigate away from. When the commit lands after that, Chrome rejects the pending evaluate with "Inspected target navigated or closed" (V8 words it "Execution context was destroyed") and the wait failed, since only "Cannot find context with specified id" was retried. The wait has no side effects, so Page.waitForSelector now re-resolves its target frame and re-issues the wait against the new document with the time left. Other evaluate failures and an exhausted budget still throw. Backport of browserbase#2983. Fixes browserbase#2982 on v3.
🦋 Changeset detectedLatest commit: 0374fac The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
Contributor
|
This PR is from an external contributor and must be approved by a stagehand team member with write access before CI can run. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Backport of #2983 to
v3. Fixes #2982 for the 3.x line.Why
page.waitForSelector()is a singleRuntime.evaluate(awaitPromise) pinned to the execution context that was current when it was issued. The typical caller issues it right after thelocator.click()that submits a form, so the context is the document about to be navigated away from. When the commit lands after the evaluate was accepted, Chrome rejects it with-32000 Inspected target navigated or closed(V8 words itExecution context was destroyed).Frame.evaluateretries onlyCannot find context with specified id, so the wait failed.What changed
packages/core/lib/v3/understudy/page.ts—waitForSelectorloops: it re-resolves its target frame, rebuilds the invocation with the time left, and re-issues the wait when the previous evaluate was rejected with one of the navigation-teardown messages. Anything else, and an exhausted budget, still throw the original error.Frame.evaluateis unchanged, since replaying an arbitrary evaluate after it ran can duplicate side effects.packages/core/tests/integration/wait-for-selector-across-navigation.spec.ts— real-browser spec: a local form target answers after 150 ms,click()thenwaitForSelector('#query').Test plan
STAGEHAND_BROWSER_TARGET=local pnpm run test:e2e -- .../wait-for-selector-across-navigation.spec.jsagainst Chrome 153: fails 3/3 runs without the change (Rejected to value: [Error: -32000 Inspected target navigated or closed]), passes with iteslint,prettier,tsc -p packages/core/tsconfig.json --noEmitSummary by cubic
Fixes
page.waitForSelector()in the v3 line so it survives a click-triggered navigation instead of failing withInspected target navigated or closed(orExecution context was destroyed) when the pending evaluate's execution context is torn down. The wait is re-issued against the new document with the remaining timeout; other errors and an exhausted timeout still throw.Written for commit 0374fac. Summary will update on new commits.