feat(evaluate): add "world" option to evaluate methods - #42635
Conversation
Allows running the page function in the isolated utility world, which shares the DOM with the page but has a separate JavaScript environment. Supported on the methods that return a serializable value: Page/Frame/Locator.evaluate, Locator.evaluateAll and Page/Frame/ElementHandle.$eval/$$eval. Methods returning a handle are not included, since utility world handles are hard to reason about.
Test results for "MCP"3 failed 8345 passed, 1376 skipped Merge workflow run. |
Test results for "tests 1"10 flaky51479 passed, 1240 skipped Merge workflow run. |
|
Hi, I'm the Playwright bot and I triaged this PR's CI failures. 🟢 CI is clear — all three failures are pre-existing flakesThe only failing job is MCP, and all three failures are known flakes on Windows that flip verdict across many unrelated SHAs. This PR only adds the DetailsOverall: No failure reaches the PR's diff. The change is scoped to Pre-existing flake / infra
Triaged by the Playwright bot - agent run |
| type: enum? | ||
| literals: | ||
| - main | ||
| - utility |
There was a problem hiding this comment.
Should we use a separate world for user evals to avoid interference with playwright internals in the utility world?
There was a problem hiding this comment.
That's too big of a change for my taste. But I will make a not for the API review.
aeebee1
into
microsoft:main
|
Dmitry Gozman (@dgozman) why do you say that handles are harder to reason about? |
Only the element handles. And they would not preserve any JS properties. I think that's not very obvious from the API standpoint, so I decided to not rush with utility-world handles 😄 |
Reverts microsoft#42635 and its follow-up microsoft#42860.
Summary
world: 'main' | 'utility'toPage/Frame/Locator.evaluate,Locator.evaluateAllandPage/Frame/ElementHandle.$eval/$$eval. The utility world shares the DOM with the page, but has an isolated JavaScript environment.$$evalresolves the elements in the requested world; when a custom selector engine forces main world resolution, the elements are moved over so the page function still runs in the requested world.