Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

Revert "feat(evaluate): add "world" option to evaluate methods" (#43040)

Dmitry Gozman95c973c90081
diff --git a/docs/src/api/class-elementhandle.md b/docs/src/api/class-elementhandle.md
index 2f32463204..7f3a147ccd 100644
--- a/docs/src/api/class-elementhandle.md
+++ b/docs/src/api/class-elementhandle.md
@@ -470,9 +470,6 @@ Assert.AreEqual("10", await tweetHandle.EvalOnSelectorAsync(".retweets", "node =
Optional argument to pass to [`param: expression`].
-### option: ElementHandle.evalOnSelector.world = %%-js-evaluate-world-%%
-* since: v1.64
-
## async method: ElementHandle.evalOnSelectorAll
* since: v1.9
* discouraged: In most cases, [`method: Locator.evaluateAll`],
@@ -541,9 +538,6 @@ Assert.AreEqual(new [] { "Hello!", "Hi!" }, await feedHandle.EvalOnSelectorAllAs
Optional argument to pass to [`param: expression`].
-### option: ElementHandle.evalOnSelectorAll.world = %%-js-evaluate-world-%%
-* since: v1.64
-
## async method: ElementHandle.fill
* since: v1.8
* discouraged: Use locator-based [`method: Locator.fill`] instead. Read more about [locators](../locators.md).
diff --git a/docs/src/api/class-frame.md b/docs/src/api/class-frame.md
index b13d3aa9e6..c5d79a3152 100644
--- a/docs/src/api/class-frame.md
+++ b/docs/src/api/class-frame.md
@@ -575,9 +575,6 @@ var html = await frame.EvalOnSelectorAsync(".main-container", "(e, suffix) => e.
Optional argument to pass to [`param: expression`].
-### option: Frame.evalOnSelector.world = %%-js-evaluate-world-%%
-* since: v1.64
-
### option: Frame.evalOnSelector.strict = %%-input-strict-%%
* since: v1.14
@@ -635,9 +632,6 @@ var divsCount = await frame.EvalOnSelectorAllAsync<bool>("div", "(divs, min) =>
Optional argument to pass to [`param: expression`].
-### option: Frame.evalOnSelectorAll.world = %%-js-evaluate-world-%%
-* since: v1.64
-
## async method: Frame.evaluate
* since: v1.8
- returns: <[Serializable]>
@@ -757,9 +751,6 @@ Optional argument to pass to [`param: expression`].
### option: Frame.evaluate.exposeFunctions = %%-js-evaluate-expose-functions-%%
* since: v1.62
-### option: Frame.evaluate.world = %%-js-evaluate-world-%%
-* since: v1.64
-
## async method: Frame.evaluateHandle
* since: v1.8
- returns: <[JSHandle]>
diff --git a/docs/src/api/class-locator.md b/docs/src/api/class-locator.md
index 64afc019d9..b9f4e062f8 100644
--- a/docs/src/api/class-locator.md
+++ b/docs/src/api/class-locator.md
@@ -1181,9 +1181,6 @@ Optional argument to pass to [`param: expression`].
### option: Locator.evaluate.exposeFunctions = %%-js-evaluate-expose-functions-%%
* since: v1.62
-### option: Locator.evaluate.world = %%-js-evaluate-world-%%
-* since: v1.64
-
### option: Locator.evaluate.timeout
* since: v1.14
* langs: python, java, csharp
@@ -1253,9 +1250,6 @@ var moreThanTen = await locator.EvaluateAllAsync<bool>("(divs, min) => divs.leng
Optional argument to pass to [`param: expression`].
-### option: Locator.evaluateAll.world = %%-js-evaluate-world-%%
-* since: v1.64
-
## async method: Locator.evaluateHandle
* since: v1.14
- returns: <[JSHandle]>
diff --git a/docs/src/api/class-page.md b/docs/src/api/class-page.md
index 03d1f91fc1..d880a95ed2 100644
--- a/docs/src/api/class-page.md
+++ b/docs/src/api/class-page.md
@@ -1424,9 +1424,6 @@ var html = await page.EvalOnSelectorAsync(".main-container", "(e, suffix) => e.o
Optional argument to pass to [`param: expression`].
-### option: Page.evalOnSelector.world = %%-js-evaluate-world-%%
-* since: v1.64
-
### option: Page.evalOnSelector.strict = %%-input-strict-%%
* since: v1.14
@@ -1482,9 +1479,6 @@ var divsCount = await page.EvalOnSelectorAllAsync<bool>("div", "(divs, min) => d
Optional argument to pass to [`param: expression`].
-### option: Page.evalOnSelectorAll.world = %%-js-evaluate-world-%%
-* since: v1.64
-
## async method: Page.evaluate
* since: v1.8
- returns: <[Serializable]>
@@ -1608,9 +1602,6 @@ Optional argument to pass to [`param: expression`].
### option: Page.evaluate.exposeFunctions = %%-js-evaluate-expose-functions-%%
* since: v1.62
-### option: Page.evaluate.world = %%-js-evaluate-world-%%
-* since: v1.64
-
## async method: Page.evaluateHandle
* since: v1.8
- returns: <[JSHandle]>
diff --git a/docs/src/api/params.md b/docs/src/api/params.md
index b303f49dc8..8611c5dc4c 100644
--- a/docs/src/api/params.md
+++ b/docs/src/api/params.md
@@ -616,12 +616,6 @@ When set to `true`, functions passed inside [`param: arg`] are exposed in the pa
When set to `true`, functions passed inside [`param: arg`] are exposed in the page and can be called from the init script. Calling one returns a [Promise] of its result. Under the hood, each function is exposed via [`method: Page.exposeFunction`], so it is technically accessible from all frames of the page. Unlike functions passed to [`method: Page.evaluate`], functions passed to an init script are exposed in every new document, so they survive navigations. Defaults to `false`, in which case functions are not serializable and are silently dropped.
-## js-evaluate-world
-* langs: js
-- `world` <[EvaluationWorld]<"main"|"utility">>
-
-The JavaScript world to evaluate the function in. `"main"` is the world where the page's own scripts run. `"utility"` is an isolated world that shares the DOM with the page, but has a separate JavaScript environment that the page's scripts cannot observe or tamper with. Defaults to `"main"`. Exposed functions are only available in the `"main"` world.
-
## js-evalonselector-pagefunction
* langs: js
- `pageFunction` <[function]\([Element]\)|[string]>
diff --git a/packages/playwright-client/types/types.d.ts b/packages/playwright-client/types/types.d.ts
index 8ba8d80428..7813b47719 100644
--- a/packages/playwright-client/types/types.d.ts
+++ b/packages/playwright-client/types/types.d.ts
@@ -134,7 +134,7 @@ export interface Page {
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-evaluate-option-expression).
* @param options
*/
- evaluate<R, Arg>(pageFunction: PageFunction<Arg, R>, arg: Arg, options?: { exposeFunctions?: boolean, world?: 'main'|'utility' }): Promise<R>;
+ evaluate<R, Arg>(pageFunction: PageFunction<Arg, R>, arg: Arg, options?: { exposeFunctions?: boolean }): Promise<R>;
/**
* Returns the value of the
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-evaluate-option-expression) invocation.
@@ -187,7 +187,7 @@ export interface Page {
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-evaluate-option-expression).
* @param options
*/
- evaluate<R>(pageFunction: PageFunction<void, R>, arg?: any, options?: { exposeFunctions?: boolean, world?: 'main'|'utility' }): Promise<R>;
+ evaluate<R>(pageFunction: PageFunction<void, R>, arg?: any, options?: { exposeFunctions?: boolean }): Promise<R>;
/**
* Returns the value of the
@@ -400,7 +400,7 @@ export interface Page {
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-option-expression).
* @param options
*/
- $eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], Arg, R>, arg: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], Arg, R>, arg: Arg): Promise<R>;
/**
* **NOTE** This method does not wait for the element to pass actionability checks and therefore can lead to the flaky tests.
* Use
@@ -433,7 +433,7 @@ export interface Page {
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-option-expression).
* @param options
*/
- $eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, Arg, R>, arg: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, Arg, R>, arg: Arg): Promise<R>;
/**
* **NOTE** This method does not wait for the element to pass actionability checks and therefore can lead to the flaky tests.
* Use
@@ -466,7 +466,7 @@ export interface Page {
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-option-expression).
* @param options
*/
- $eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], void, R>, arg?: any, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], void, R>, arg?: any): Promise<R>;
/**
* **NOTE** This method does not wait for the element to pass actionability checks and therefore can lead to the flaky tests.
* Use
@@ -499,11 +499,11 @@ export interface Page {
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-option-expression).
* @param options
*/
- $eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, void, R>, arg?: any, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, void, R>, arg?: any): Promise<R>;
/**
* **NOTE** In most cases,
- * [locator.evaluateAll(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
+ * [locator.evaluateAll(pageFunction[, arg])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
* other [Locator](https://playwright.dev/docs/api/class-locator) helper methods and web-first assertions do a better
* job.
*
@@ -516,7 +516,7 @@ export interface Page {
*
* If [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all-option-expression) returns
* a [Promise], then
- * [page.$$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all)
+ * [page.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all)
* would wait for the promise to resolve and return its value.
*
* **Usage**
@@ -529,12 +529,11 @@ export interface Page {
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all-option-expression).
- * @param options
*/
- $$eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], Arg, R>, arg: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $$eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], Arg, R>, arg: Arg): Promise<R>;
/**
* **NOTE** In most cases,
- * [locator.evaluateAll(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
+ * [locator.evaluateAll(pageFunction[, arg])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
* other [Locator](https://playwright.dev/docs/api/class-locator) helper methods and web-first assertions do a better
* job.
*
@@ -547,7 +546,7 @@ export interface Page {
*
* If [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all-option-expression) returns
* a [Promise], then
- * [page.$$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all)
+ * [page.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all)
* would wait for the promise to resolve and return its value.
*
* **Usage**
@@ -560,12 +559,11 @@ export interface Page {
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all-option-expression).
- * @param options
*/
- $$eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], Arg, R>, arg: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $$eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], Arg, R>, arg: Arg): Promise<R>;
/**
* **NOTE** In most cases,
- * [locator.evaluateAll(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
+ * [locator.evaluateAll(pageFunction[, arg])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
* other [Locator](https://playwright.dev/docs/api/class-locator) helper methods and web-first assertions do a better
* job.
*
@@ -578,7 +576,7 @@ export interface Page {
*
* If [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all-option-expression) returns
* a [Promise], then
- * [page.$$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all)
+ * [page.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all)
* would wait for the promise to resolve and return its value.
*
* **Usage**
@@ -591,12 +589,11 @@ export interface Page {
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all-option-expression).
- * @param options
*/
- $$eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], void, R>, arg?: any, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $$eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], void, R>, arg?: any): Promise<R>;
/**
* **NOTE** In most cases,
- * [locator.evaluateAll(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
+ * [locator.evaluateAll(pageFunction[, arg])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
* other [Locator](https://playwright.dev/docs/api/class-locator) helper methods and web-first assertions do a better
* job.
*
@@ -609,7 +606,7 @@ export interface Page {
*
* If [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all-option-expression) returns
* a [Promise], then
- * [page.$$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all)
+ * [page.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all)
* would wait for the promise to resolve and return its value.
*
* **Usage**
@@ -622,9 +619,8 @@ export interface Page {
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all-option-expression).
- * @param options
*/
- $$eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], void, R>, arg?: any, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $$eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], void, R>, arg?: any): Promise<R>;
/**
* Returns when the
@@ -5988,7 +5984,7 @@ export interface Frame {
* [`pageFunction`](https://playwright.dev/docs/api/class-frame#frame-evaluate-option-expression).
* @param options
*/
- evaluate<R, Arg>(pageFunction: PageFunction<Arg, R>, arg: Arg, options?: { exposeFunctions?: boolean, world?: 'main'|'utility' }): Promise<R>;
+ evaluate<R, Arg>(pageFunction: PageFunction<Arg, R>, arg: Arg, options?: { exposeFunctions?: boolean }): Promise<R>;
/**
* Returns the return value of
* [`pageFunction`](https://playwright.dev/docs/api/class-frame#frame-evaluate-option-expression).
@@ -6037,7 +6033,7 @@ export interface Frame {
* [`pageFunction`](https://playwright.dev/docs/api/class-frame#frame-evaluate-option-expression).
* @param options
*/
- evaluate<R>(pageFunction: PageFunction<void, R>, arg?: any, options?: { exposeFunctions?: boolean, world?: 'main'|'utility' }): Promise<R>;
+ evaluate<R>(pageFunction: PageFunction<void, R>, arg?: any, options?: { exposeFunctions?: boolean }): Promise<R>;
/**
* Returns the return value of
@@ -6230,7 +6226,7 @@ export interface Frame {
* [`pageFunction`](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-option-expression).
* @param options
*/
- $eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], Arg, R>, arg: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], Arg, R>, arg: Arg): Promise<R>;
/**
* **NOTE** This method does not wait for the element to pass the actionability checks and therefore can lead to the flaky
* tests. Use
@@ -6263,7 +6259,7 @@ export interface Frame {
* [`pageFunction`](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-option-expression).
* @param options
*/
- $eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, Arg, R>, arg: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, Arg, R>, arg: Arg): Promise<R>;
/**
* **NOTE** This method does not wait for the element to pass the actionability checks and therefore can lead to the flaky
* tests. Use
@@ -6296,7 +6292,7 @@ export interface Frame {
* [`pageFunction`](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-option-expression).
* @param options
*/
- $eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], void, R>, arg?: any, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], void, R>, arg?: any): Promise<R>;
/**
* **NOTE** This method does not wait for the element to pass the actionability checks and therefore can lead to the flaky
* tests. Use
@@ -6329,11 +6325,11 @@ export interface Frame {
* [`pageFunction`](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-option-expression).
* @param options
*/
- $eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, void, R>, arg?: any, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, void, R>, arg?: any): Promise<R>;
/**
* **NOTE** In most cases,
- * [locator.evaluateAll(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
+ * [locator.evaluateAll(pageFunction[, arg])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
* other [Locator](https://playwright.dev/docs/api/class-locator) helper methods and web-first assertions do a better
* job.
*
@@ -6346,7 +6342,7 @@ export interface Frame {
*
* If [`pageFunction`](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-all-option-expression)
* returns a [Promise], then
- * [frame.$$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-all)
+ * [frame.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-all)
* would wait for the promise to resolve and return its value.
*
* **Usage**
@@ -6359,12 +6355,11 @@ export interface Frame {
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-all-option-expression).
- * @param options
*/
- $$eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], Arg, R>, arg: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $$eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], Arg, R>, arg: Arg): Promise<R>;
/**
* **NOTE** In most cases,
- * [locator.evaluateAll(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
+ * [locator.evaluateAll(pageFunction[, arg])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
* other [Locator](https://playwright.dev/docs/api/class-locator) helper methods and web-first assertions do a better
* job.
*
@@ -6377,7 +6372,7 @@ export interface Frame {
*
* If [`pageFunction`](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-all-option-expression)
* returns a [Promise], then
- * [frame.$$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-all)
+ * [frame.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-all)
* would wait for the promise to resolve and return its value.
*
* **Usage**
@@ -6390,12 +6385,11 @@ export interface Frame {
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-all-option-expression).
- * @param options
*/
- $$eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], Arg, R>, arg: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $$eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], Arg, R>, arg: Arg): Promise<R>;
/**
* **NOTE** In most cases,
- * [locator.evaluateAll(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
+ * [locator.evaluateAll(pageFunction[, arg])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
* other [Locator](https://playwright.dev/docs/api/class-locator) helper methods and web-first assertions do a better
* job.
*
@@ -6408,7 +6402,7 @@ export interface Frame {
*
* If [`pageFunction`](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-all-option-expression)
* returns a [Promise], then
- * [frame.$$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-all)
+ * [frame.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-all)
* would wait for the promise to resolve and return its value.
*
* **Usage**
@@ -6421,12 +6415,11 @@ export interface Frame {
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-all-option-expression).
- * @param options
*/
- $$eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], void, R>, arg?: any, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $$eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], void, R>, arg?: any): Promise<R>;
/**
* **NOTE** In most cases,
- * [locator.evaluateAll(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
+ * [locator.evaluateAll(pageFunction[, arg])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
* other [Locator](https://playwright.dev/docs/api/class-locator) helper methods and web-first assertions do a better
* job.
*
@@ -6439,7 +6432,7 @@ export interface Frame {
*
* If [`pageFunction`](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-all-option-expression)
* returns a [Promise], then
- * [frame.$$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-all)
+ * [frame.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-all)
* would wait for the promise to resolve and return its value.
*
* **Usage**
@@ -6452,9 +6445,8 @@ export interface Frame {
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-all-option-expression).
- * @param options
*/
- $$eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], void, R>, arg?: any, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $$eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], void, R>, arg?: any): Promise<R>;
/**
* Returns when the
@@ -12500,7 +12492,7 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
* If
* [`pageFunction`](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-option-expression)
* returns a [Promise], then
- * [elementHandle.$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector)
+ * [elementHandle.$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector)
* would wait for the promise to resolve and return its value.
*
* **Usage**
@@ -12515,9 +12507,8 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-option-expression).
- * @param options
*/
- $eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], Arg, R>, arg: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], Arg, R>, arg: Arg): Promise<R>;
/**
* **NOTE** This method does not wait for the element to pass actionability checks and therefore can lead to the flaky tests.
* Use
@@ -12535,7 +12526,7 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
* If
* [`pageFunction`](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-option-expression)
* returns a [Promise], then
- * [elementHandle.$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector)
+ * [elementHandle.$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector)
* would wait for the promise to resolve and return its value.
*
* **Usage**
@@ -12550,9 +12541,8 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-option-expression).
- * @param options
*/
- $eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, Arg, R>, arg: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, Arg, R>, arg: Arg): Promise<R>;
/**
* **NOTE** This method does not wait for the element to pass actionability checks and therefore can lead to the flaky tests.
* Use
@@ -12570,7 +12560,7 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
* If
* [`pageFunction`](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-option-expression)
* returns a [Promise], then
- * [elementHandle.$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector)
+ * [elementHandle.$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector)
* would wait for the promise to resolve and return its value.
*
* **Usage**
@@ -12585,9 +12575,8 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-option-expression).
- * @param options
*/
- $eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], void, R>, arg?: any, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], void, R>, arg?: any): Promise<R>;
/**
* **NOTE** This method does not wait for the element to pass actionability checks and therefore can lead to the flaky tests.
* Use
@@ -12605,7 +12594,7 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
* If
* [`pageFunction`](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-option-expression)
* returns a [Promise], then
- * [elementHandle.$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector)
+ * [elementHandle.$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector)
* would wait for the promise to resolve and return its value.
*
* **Usage**
@@ -12620,13 +12609,12 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-option-expression).
- * @param options
*/
- $eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, void, R>, arg?: any, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, void, R>, arg?: any): Promise<R>;
/**
* **NOTE** In most cases,
- * [locator.evaluateAll(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
+ * [locator.evaluateAll(pageFunction[, arg])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
* other [Locator](https://playwright.dev/docs/api/class-locator) helper methods and web-first assertions do a better
* job.
*
@@ -12640,7 +12628,7 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
* If
* [`pageFunction`](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-all-option-expression)
* returns a [Promise], then
- * [elementHandle.$$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-all)
+ * [elementHandle.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-all)
* would wait for the promise to resolve and return its value.
*
* **Usage**
@@ -12663,12 +12651,11 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-all-option-expression).
- * @param options
*/
- $$eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], Arg, R>, arg: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $$eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], Arg, R>, arg: Arg): Promise<R>;
/**
* **NOTE** In most cases,
- * [locator.evaluateAll(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
+ * [locator.evaluateAll(pageFunction[, arg])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
* other [Locator](https://playwright.dev/docs/api/class-locator) helper methods and web-first assertions do a better
* job.
*
@@ -12682,7 +12669,7 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
* If
* [`pageFunction`](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-all-option-expression)
* returns a [Promise], then
- * [elementHandle.$$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-all)
+ * [elementHandle.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-all)
* would wait for the promise to resolve and return its value.
*
* **Usage**
@@ -12705,12 +12692,11 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-all-option-expression).
- * @param options
*/
- $$eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], Arg, R>, arg: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $$eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], Arg, R>, arg: Arg): Promise<R>;
/**
* **NOTE** In most cases,
- * [locator.evaluateAll(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
+ * [locator.evaluateAll(pageFunction[, arg])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
* other [Locator](https://playwright.dev/docs/api/class-locator) helper methods and web-first assertions do a better
* job.
*
@@ -12724,7 +12710,7 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
* If
* [`pageFunction`](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-all-option-expression)
* returns a [Promise], then
- * [elementHandle.$$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-all)
+ * [elementHandle.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-all)
* would wait for the promise to resolve and return its value.
*
* **Usage**
@@ -12747,12 +12733,11 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-all-option-expression).
- * @param options
*/
- $$eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], void, R>, arg?: any, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $$eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], void, R>, arg?: any): Promise<R>;
/**
* **NOTE** In most cases,
- * [locator.evaluateAll(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
+ * [locator.evaluateAll(pageFunction[, arg])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
* other [Locator](https://playwright.dev/docs/api/class-locator) helper methods and web-first assertions do a better
* job.
*
@@ -12766,7 +12751,7 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
* If
* [`pageFunction`](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-all-option-expression)
* returns a [Promise], then
- * [elementHandle.$$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-all)
+ * [elementHandle.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-all)
* would wait for the promise to resolve and return its value.
*
* **Usage**
@@ -12789,9 +12774,8 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-all-option-expression).
- * @param options
*/
- $$eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], void, R>, arg?: any, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $$eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], void, R>, arg?: any): Promise<R>;
/**
* **NOTE** Use web assertions that assert visibility or a locator-based
@@ -14366,7 +14350,7 @@ export interface Locator {
* [`pageFunction`](https://playwright.dev/docs/api/class-locator#locator-evaluate-option-expression).
* @param options
*/
- evaluate<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(pageFunction: PageFunctionOn<E, Arg, R>, arg?: Arg, options?: { timeout?: number, signal?: AbortSignal, exposeFunctions?: boolean, world?: 'main'|'utility' }): Promise<R>;
+ evaluate<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(pageFunction: PageFunctionOn<E, Arg, R>, arg?: Arg, options?: { timeout?: number, signal?: AbortSignal, exposeFunctions?: boolean }): Promise<R>;
/**
* Execute JavaScript code in the page, taking the matching element as an argument, and return a
* [JSHandle](https://playwright.dev/docs/api/class-jshandle) with the result.
@@ -14427,9 +14411,8 @@ export interface Locator {
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-locator#locator-evaluate-all-option-expression).
- * @param options
*/
- evaluateAll<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(pageFunction: PageFunctionOn<E[], Arg, R>, arg?: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
+ evaluateAll<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(pageFunction: PageFunctionOn<E[], Arg, R>, arg?: Arg): Promise<R>;
/**
* Returns when
* [`pageFunction`](https://playwright.dev/docs/api/class-locator#locator-wait-for-function-option-expression) returns
diff --git a/packages/playwright-core/src/client/channels.d.ts b/packages/playwright-core/src/client/channels.d.ts
index bc133ac010..6b2d26cf7e 100644
--- a/packages/playwright-core/src/client/channels.d.ts
+++ b/packages/playwright-core/src/client/channels.d.ts
@@ -2344,12 +2344,10 @@ export type FrameEvalOnSelectorParams = {
expression: string,
isFunction?: boolean,
arg: SerializedArgument,
- world?: 'main' | 'utility',
};
export type FrameEvalOnSelectorOptions = {
strict?: boolean,
isFunction?: boolean,
- world?: 'main' | 'utility',
};
export type FrameEvalOnSelectorResult = {
value: SerializedValue,
@@ -2359,11 +2357,9 @@ export type FrameEvalOnSelectorAllParams = {
expression: string,
isFunction?: boolean,
arg: SerializedArgument,
- world?: 'main' | 'utility',
};
export type FrameEvalOnSelectorAllOptions = {
isFunction?: boolean,
- world?: 'main' | 'utility',
};
export type FrameEvalOnSelectorAllResult = {
value: SerializedValue,
@@ -2574,11 +2570,9 @@ export type FrameEvaluateExpressionParams = {
expression: string,
isFunction?: boolean,
arg: SerializedArgument,
- world?: 'main' | 'utility',
};
export type FrameEvaluateExpressionOptions = {
isFunction?: boolean,
- world?: 'main' | 'utility',
};
export type FrameEvaluateExpressionResult = {
value: SerializedValue,
@@ -3064,11 +3058,9 @@ export type JSHandleEvaluateExpressionParams = {
expression: string,
isFunction?: boolean,
arg: SerializedArgument,
- world?: 'main' | 'utility',
};
export type JSHandleEvaluateExpressionOptions = {
isFunction?: boolean,
- world?: 'main' | 'utility',
};
export type JSHandleEvaluateExpressionResult = {
value: SerializedValue,
@@ -3160,12 +3152,10 @@ export type ElementHandleEvalOnSelectorParams = {
expression: string,
isFunction?: boolean,
arg: SerializedArgument,
- world?: 'main' | 'utility',
};
export type ElementHandleEvalOnSelectorOptions = {
strict?: boolean,
isFunction?: boolean,
- world?: 'main' | 'utility',
};
export type ElementHandleEvalOnSelectorResult = {
value: SerializedValue,
@@ -3175,11 +3165,9 @@ export type ElementHandleEvalOnSelectorAllParams = {
expression: string,
isFunction?: boolean,
arg: SerializedArgument,
- world?: 'main' | 'utility',
};
export type ElementHandleEvalOnSelectorAllOptions = {
isFunction?: boolean,
- world?: 'main' | 'utility',
};
export type ElementHandleEvalOnSelectorAllResult = {
value: SerializedValue,
diff --git a/packages/playwright-core/src/client/elementHandle.ts b/packages/playwright-core/src/client/elementHandle.ts
index 7cb0aa25ff..4cee41bcf5 100644
--- a/packages/playwright-core/src/client/elementHandle.ts
+++ b/packages/playwright-core/src/client/elementHandle.ts
@@ -22,14 +22,13 @@ import { assert } from '@isomorphic/assert';
import { isString } from '@isomorphic/rtti';
import { getMimeTypeForPath } from '@isomorphic/mimeType';
import { Frame } from './frame';
-import { JSHandle, assertEvaluateOptions, parseResult, serializeArgument } from './jsHandle';
+import { JSHandle, parseResult, serializeArgument } from './jsHandle';
import { fileUploadSizeLimit, mkdirIfNeeded } from './fileUtils';
import { WritableStream } from './writableStream';
import { kNoTimeout } from './timeoutSettings';
import type { BrowserContext } from './browserContext';
import type { ChannelOwner } from './channelOwner';
-import type { WorldOptions } from './jsHandle';
import type { Locator } from './locator';
import type { FilePayload, Rect, SelectOption, SelectOptionOptions, TimeoutOptions } from './types';
import type * as structs from '../../types/structs';
@@ -217,15 +216,13 @@ export class ElementHandle<T extends Node = Node> extends JSHandle<T> implements
return result.elements.map(h => ElementHandle.from(h) as ElementHandle<SVGElement | HTMLElement>);
}
- async $eval<R, Arg>(selector: string, pageFunction: structs.PageFunctionOn<Element, Arg, R>, arg?: Arg, options?: WorldOptions): Promise<R> {
- assertEvaluateOptions(options);
- const result = await this._elementChannel.evalOnSelector({ selector, expression: String(pageFunction), isFunction: typeof pageFunction === 'function', arg: serializeArgument(arg), world: options?.world }, kNoTimeout);
+ async $eval<R, Arg>(selector: string, pageFunction: structs.PageFunctionOn<Element, Arg, R>, arg?: Arg): Promise<R> {
+ const result = await this._elementChannel.evalOnSelector({ selector, expression: String(pageFunction), isFunction: typeof pageFunction === 'function', arg: serializeArgument(arg) }, kNoTimeout);
return parseResult(result.value);
}
- async $$eval<R, Arg>(selector: string, pageFunction: structs.PageFunctionOn<Element[], Arg, R>, arg?: Arg, options?: WorldOptions): Promise<R> {
- assertEvaluateOptions(options);
- const result = await this._elementChannel.evalOnSelectorAll({ selector, expression: String(pageFunction), isFunction: typeof pageFunction === 'function', arg: serializeArgument(arg), world: options?.world }, kNoTimeout);
+ async $$eval<R, Arg>(selector: string, pageFunction: structs.PageFunctionOn<Element[], Arg, R>, arg?: Arg): Promise<R> {
+ const result = await this._elementChannel.evalOnSelectorAll({ selector, expression: String(pageFunction), isFunction: typeof pageFunction === 'function', arg: serializeArgument(arg) }, kNoTimeout);
return parseResult(result.value);
}
diff --git a/packages/playwright-core/src/client/frame.ts b/packages/playwright-core/src/client/frame.ts
index 1dea08fa16..80250a6118 100644
--- a/packages/playwright-core/src/client/frame.ts
+++ b/packages/playwright-core/src/client/frame.ts
@@ -36,7 +36,7 @@ import { Waiter } from './waiter';
import { WebMCP } from './webmcp';
import { TimeoutSettings, kNoTimeout } from './timeoutSettings';
-import type { EvaluateOptions, ExposeFunctionsOptions, WorldOptions } from './jsHandle';
+import type { EvaluateOptions } from './jsHandle';
import type { LocatorOptions } from './locator';
import type { Page } from './page';
import type { DropPayload, FilePayload, LifecycleEvent, SelectOption, SelectOptionOptions, StrictOptions, TimeoutOptions, WaitForFunctionOptions } from './types';
@@ -210,7 +210,7 @@ export class Frame extends ChannelOwner<channels.FrameChannel> implements api.Fr
return ElementHandle.from((await this._channel.frameElement({}, kNoTimeout)).element);
}
- async evaluateHandle<R, Arg>(pageFunction: structs.PageFunction<Arg, R>, arg?: Arg, options?: ExposeFunctionsOptions): Promise<structs.SmartHandle<R>> {
+ async evaluateHandle<R, Arg>(pageFunction: structs.PageFunction<Arg, R>, arg?: Arg, options?: EvaluateOptions): Promise<structs.SmartHandle<R>> {
assertMaxArguments(arguments.length, 3);
assertEvaluateOptions(options);
const serializedArg = options?.exposeFunctions ? await serializeArgumentWithCallbacks(this, this._page, arg) : serializeArgument(arg);
@@ -222,7 +222,7 @@ export class Frame extends ChannelOwner<channels.FrameChannel> implements api.Fr
assertMaxArguments(arguments.length, 3);
assertEvaluateOptions(options);
const serializedArg = options?.exposeFunctions ? await serializeArgumentWithCallbacks(this, this._page, arg) : serializeArgument(arg);
- const result = await this._channel.evaluateExpression({ expression: String(pageFunction), isFunction: typeof pageFunction === 'function', arg: serializedArg, world: options?.world }, kNoTimeout);
+ const result = await this._channel.evaluateExpression({ expression: String(pageFunction), isFunction: typeof pageFunction === 'function', arg: serializedArg }, kNoTimeout);
return parseResult(result.value);
}
@@ -252,17 +252,15 @@ export class Frame extends ChannelOwner<channels.FrameChannel> implements api.Fr
await this._channel.dispatchEvent({ selector, type, eventInit: serializeArgument(eventInit), ...options }, this._timeout(options));
}
- async $eval<R, Arg>(selector: string, pageFunction: structs.PageFunctionOn<Element, Arg, R>, arg?: Arg, options?: WorldOptions): Promise<R> {
- assertMaxArguments(arguments.length, 4);
- assertEvaluateOptions(options);
- const result = await this._channel.evalOnSelector({ selector, expression: String(pageFunction), isFunction: typeof pageFunction === 'function', arg: serializeArgument(arg), world: options?.world }, kNoTimeout);
+ async $eval<R, Arg>(selector: string, pageFunction: structs.PageFunctionOn<Element, Arg, R>, arg?: Arg): Promise<R> {
+ assertMaxArguments(arguments.length, 3);
+ const result = await this._channel.evalOnSelector({ selector, expression: String(pageFunction), isFunction: typeof pageFunction === 'function', arg: serializeArgument(arg) }, kNoTimeout);
return parseResult(result.value);
}
- async $$eval<R, Arg>(selector: string, pageFunction: structs.PageFunctionOn<Element[], Arg, R>, arg?: Arg, options?: WorldOptions): Promise<R> {
- assertMaxArguments(arguments.length, 4);
- assertEvaluateOptions(options);
- const result = await this._channel.evalOnSelectorAll({ selector, expression: String(pageFunction), isFunction: typeof pageFunction === 'function', arg: serializeArgument(arg), world: options?.world }, kNoTimeout);
+ async $$eval<R, Arg>(selector: string, pageFunction: structs.PageFunctionOn<Element[], Arg, R>, arg?: Arg): Promise<R> {
+ assertMaxArguments(arguments.length, 3);
+ const result = await this._channel.evalOnSelectorAll({ selector, expression: String(pageFunction), isFunction: typeof pageFunction === 'function', arg: serializeArgument(arg) }, kNoTimeout);
return parseResult(result.value);
}
diff --git a/packages/playwright-core/src/client/jsHandle.ts b/packages/playwright-core/src/client/jsHandle.ts
index 8a73882ce7..d471ee6565 100644
--- a/packages/playwright-core/src/client/jsHandle.ts
+++ b/packages/playwright-core/src/client/jsHandle.ts
@@ -40,19 +40,14 @@ export class JSHandle<T = any> extends ChannelOwner<channels.JSHandleChannel> im
this._channel.on('previewUpdated', ({ preview }) => this._preview = preview);
}
- async evaluate<R, Arg>(pageFunction: structs.PageFunctionOn<T, Arg, R>, arg?: Arg, options?: ExposeFunctionsOptions): Promise<R> {
- assertEvaluateOptions(options);
- return await this._evaluate(pageFunction, arg, { exposeFunctions: options?.exposeFunctions });
- }
-
- async _evaluate<R, Arg>(pageFunction: structs.PageFunctionOn<T, Arg, R>, arg?: Arg, options?: EvaluateOptions): Promise<R> {
+ async evaluate<R, Arg>(pageFunction: structs.PageFunctionOn<T, Arg, R>, arg?: Arg, options?: EvaluateOptions): Promise<R> {
assertEvaluateOptions(options);
const serializedArg = options?.exposeFunctions ? await serializeArgumentWithCallbacks(this, this._parentOfType('Page') as Page | undefined, arg) : serializeArgument(arg);
- const result = await this._channel.evaluateExpression({ expression: String(pageFunction), isFunction: typeof pageFunction === 'function', arg: serializedArg, world: options?.world }, kNoTimeout);
+ const result = await this._channel.evaluateExpression({ expression: String(pageFunction), isFunction: typeof pageFunction === 'function', arg: serializedArg }, kNoTimeout);
return parseResult(result.value);
}
- async evaluateHandle<R, Arg>(pageFunction: structs.PageFunctionOn<T, Arg, R>, arg?: Arg, options?: ExposeFunctionsOptions): Promise<structs.SmartHandle<R>> {
+ async evaluateHandle<R, Arg>(pageFunction: structs.PageFunctionOn<T, Arg, R>, arg?: Arg, options?: EvaluateOptions): Promise<structs.SmartHandle<R>> {
assertEvaluateOptions(options);
const serializedArg = options?.exposeFunctions ? await serializeArgumentWithCallbacks(this, this._parentOfType('Page') as Page | undefined, arg) : serializeArgument(arg);
const result = await this._channel.evaluateExpressionHandle({ expression: String(pageFunction), isFunction: typeof pageFunction === 'function', arg: serializedArg }, kNoTimeout);
@@ -116,9 +111,8 @@ export function serializeArgument(arg: any, registerCallback?: (callback: Functi
return { value, handles };
}
-export type WorldOptions = { world?: 'main' | 'utility' };
export type ExposeFunctionsOptions = { exposeFunctions?: boolean };
-export type EvaluateOptions = ExposeFunctionsOptions & WorldOptions;
+export type EvaluateOptions = ExposeFunctionsOptions;
export async function serializeArgumentWithCallbacks(owner: ChannelOwner<any>, page: Page | undefined, arg: any): Promise<channels.SerializedArgument> {
return await owner._wrapApiCall(async () => {
@@ -147,6 +141,4 @@ export function assertMaxArguments(count: number, max: number): asserts count {
export function assertEvaluateOptions(options: any) {
if (options !== undefined && (typeof options !== 'object' || options === null || Array.isArray(options)))
throw new Error('Too many arguments. If you need to pass more than 1 argument to the function wrap them in an object.');
- if (options?.exposeFunctions && options?.world === 'utility')
- throw new Error('Option "exposeFunctions" is not supported in the "utility" world.');
}
diff --git a/packages/playwright-core/src/client/locator.ts b/packages/playwright-core/src/client/locator.ts
index caf2ba828a..da55f7ba4f 100644
--- a/packages/playwright-core/src/client/locator.ts
+++ b/packages/playwright-core/src/client/locator.ts
@@ -28,7 +28,7 @@ import { DisposableStub } from './disposable';
import { kNoTimeout } from './timeoutSettings';
import type { ExpectResult, Frame } from './frame';
-import type { EvaluateOptions, ExposeFunctionsOptions, WorldOptions } from './jsHandle';
+import type { EvaluateOptions } from './jsHandle';
import type { DropPayload, FilePayload, FrameExpectParams, Rect, SelectOption, SelectOptionOptions, TimeoutOptions } from './types';
import type * as structs from '../../types/structs';
import type * as api from '../../types/types';
@@ -138,14 +138,14 @@ export class Locator implements api.Locator {
}
async evaluate<R, Arg>(pageFunction: structs.PageFunctionOn<SVGElement | HTMLElement, Arg, R>, arg?: Arg, options?: TimeoutOptions & EvaluateOptions): Promise<R> {
- return await this._withElement(h => h._evaluate(pageFunction, arg, options), { title: 'Evaluate', timeout: options?.timeout, signal: options?.signal });
+ return await this._withElement(h => h.evaluate(pageFunction, arg, options), { title: 'Evaluate', timeout: options?.timeout, signal: options?.signal });
}
- async evaluateAll<R, Arg>(pageFunction: structs.PageFunctionOn<Element[], Arg, R>, arg?: Arg, options?: WorldOptions): Promise<R> {
- return await this._frame.$$eval(this._selector, pageFunction, arg, options);
+ async evaluateAll<R, Arg>(pageFunction: structs.PageFunctionOn<Element[], Arg, R>, arg?: Arg): Promise<R> {
+ return await this._frame.$$eval(this._selector, pageFunction, arg);
}
- async evaluateHandle<R, Arg>(pageFunction: structs.PageFunctionOn<any, Arg, R>, arg?: Arg, options?: TimeoutOptions & ExposeFunctionsOptions): Promise<structs.SmartHandle<R>> {
+ async evaluateHandle<R, Arg>(pageFunction: structs.PageFunctionOn<any, Arg, R>, arg?: Arg, options?: TimeoutOptions & EvaluateOptions): Promise<structs.SmartHandle<R>> {
return await this._withElement(h => h.evaluateHandle(pageFunction, arg, options), { title: 'Evaluate', timeout: options?.timeout, signal: options?.signal });
}
diff --git a/packages/playwright-core/src/client/page.ts b/packages/playwright-core/src/client/page.ts
index 9b08fbf329..ac106def73 100644
--- a/packages/playwright-core/src/client/page.ts
+++ b/packages/playwright-core/src/client/page.ts
@@ -50,7 +50,7 @@ import { TimeoutSettings, kNoTimeout } from './timeoutSettings';
import { mkdirIfNeeded } from './fileUtils';
import { ConsoleMessage } from './consoleMessage';
import type { BrowserContext } from './browserContext';
-import type { EvaluateOptions, ExposeFunctionsOptions, WorldOptions } from './jsHandle';
+import type { EvaluateOptions, ExposeFunctionsOptions } from './jsHandle';
import type { Clock } from './clock';
import type { APIRequestContext } from './fetch';
import type { WaitForNavigationOptions } from './frame';
@@ -341,19 +341,19 @@ export class Page extends ChannelOwner<channels.PageChannel> implements api.Page
return await this._mainFrame.dispatchEvent(selector, type, eventInit, options);
}
- async evaluateHandle<R, Arg>(pageFunction: structs.PageFunction<Arg, R>, arg?: Arg, options?: ExposeFunctionsOptions): Promise<structs.SmartHandle<R>> {
+ async evaluateHandle<R, Arg>(pageFunction: structs.PageFunction<Arg, R>, arg?: Arg, options?: EvaluateOptions): Promise<structs.SmartHandle<R>> {
assertMaxArguments(arguments.length, 3);
return await this._mainFrame.evaluateHandle(pageFunction, arg, options);
}
- async $eval<R, Arg>(selector: string, pageFunction: structs.PageFunctionOn<Element, Arg, R>, arg?: Arg, options?: WorldOptions): Promise<R> {
- assertMaxArguments(arguments.length, 4);
- return await this._mainFrame.$eval(selector, pageFunction, arg, options);
+ async $eval<R, Arg>(selector: string, pageFunction: structs.PageFunctionOn<Element, Arg, R>, arg?: Arg): Promise<R> {
+ assertMaxArguments(arguments.length, 3);
+ return await this._mainFrame.$eval(selector, pageFunction, arg);
}
- async $$eval<R, Arg>(selector: string, pageFunction: structs.PageFunctionOn<Element[], Arg, R>, arg?: Arg, options?: WorldOptions): Promise<R> {
- assertMaxArguments(arguments.length, 4);
- return await this._mainFrame.$$eval(selector, pageFunction, arg, options);
+ async $$eval<R, Arg>(selector: string, pageFunction: structs.PageFunctionOn<Element[], Arg, R>, arg?: Arg): Promise<R> {
+ assertMaxArguments(arguments.length, 3);
+ return await this._mainFrame.$$eval(selector, pageFunction, arg);
}
async $$(selector: string): Promise<ElementHandle<SVGElement | HTMLElement>[]> {
diff --git a/packages/playwright-core/src/server/channels.d.ts b/packages/playwright-core/src/server/channels.d.ts
index adefbefd2a..f16e3626df 100644
--- a/packages/playwright-core/src/server/channels.d.ts
+++ b/packages/playwright-core/src/server/channels.d.ts
@@ -2345,12 +2345,10 @@ export type FrameEvalOnSelectorParams = {
expression: string,
isFunction?: boolean,
arg: SerializedArgument,
- world?: 'main' | 'utility',
};
export type FrameEvalOnSelectorOptions = {
strict?: boolean,
isFunction?: boolean,
- world?: 'main' | 'utility',
};
export type FrameEvalOnSelectorResult = {
value: SerializedValue,
@@ -2360,11 +2358,9 @@ export type FrameEvalOnSelectorAllParams = {
expression: string,
isFunction?: boolean,
arg: SerializedArgument,
- world?: 'main' | 'utility',
};
export type FrameEvalOnSelectorAllOptions = {
isFunction?: boolean,
- world?: 'main' | 'utility',
};
export type FrameEvalOnSelectorAllResult = {
value: SerializedValue,
@@ -2575,11 +2571,9 @@ export type FrameEvaluateExpressionParams = {
expression: string,
isFunction?: boolean,
arg: SerializedArgument,
- world?: 'main' | 'utility',
};
export type FrameEvaluateExpressionOptions = {
isFunction?: boolean,
- world?: 'main' | 'utility',
};
export type FrameEvaluateExpressionResult = {
value: SerializedValue,
@@ -3065,11 +3059,9 @@ export type JSHandleEvaluateExpressionParams = {
expression: string,
isFunction?: boolean,
arg: SerializedArgument,
- world?: 'main' | 'utility',
};
export type JSHandleEvaluateExpressionOptions = {
isFunction?: boolean,
- world?: 'main' | 'utility',
};
export type JSHandleEvaluateExpressionResult = {
value: SerializedValue,
@@ -3161,12 +3153,10 @@ export type ElementHandleEvalOnSelectorParams = {
expression: string,
isFunction?: boolean,
arg: SerializedArgument,
- world?: 'main' | 'utility',
};
export type ElementHandleEvalOnSelectorOptions = {
strict?: boolean,
isFunction?: boolean,
- world?: 'main' | 'utility',
};
export type ElementHandleEvalOnSelectorResult = {
value: SerializedValue,
@@ -3176,11 +3166,9 @@ export type ElementHandleEvalOnSelectorAllParams = {
expression: string,
isFunction?: boolean,
arg: SerializedArgument,
- world?: 'main' | 'utility',
};
export type ElementHandleEvalOnSelectorAllOptions = {
isFunction?: boolean,
- world?: 'main' | 'utility',
};
export type ElementHandleEvalOnSelectorAllResult = {
value: SerializedValue,
diff --git a/packages/playwright-core/src/server/dispatchers/elementHandlerDispatcher.ts b/packages/playwright-core/src/server/dispatchers/elementHandlerDispatcher.ts
index f724a14775..c135aff5eb 100644
--- a/packages/playwright-core/src/server/dispatchers/elementHandlerDispatcher.ts
+++ b/packages/playwright-core/src/server/dispatchers/elementHandlerDispatcher.ts
@@ -55,11 +55,6 @@ export class ElementHandleDispatcher extends JSHandleDispatcher<FrameDispatcher>
this._elementHandle = elementHandle;
}
- override async evaluateExpression(params: channels.JSHandleEvaluateExpressionParams, progress: Progress): Promise<channels.JSHandleEvaluateExpressionResult> {
- const value = await this._elementHandle.evaluateExpression(progress, params.expression, { isFunction: params.isFunction, world: params.world }, parseArgument(params.arg));
- return { value: serializeResult(value) };
- }
-
async ownerFrame(params: channels.ElementHandleOwnerFrameParams, progress: Progress): Promise<channels.ElementHandleOwnerFrameResult> {
const frame = await this._elementHandle.ownerFrame(progress);
return { frame: frame ? FrameDispatcher.from(this._browserContextDispatcher(), frame) : undefined };
@@ -202,11 +197,11 @@ export class ElementHandleDispatcher extends JSHandleDispatcher<FrameDispatcher>
}
async evalOnSelector(params: channels.ElementHandleEvalOnSelectorParams, progress: Progress): Promise<channels.ElementHandleEvalOnSelectorResult> {
- return { value: serializeResult(await this._elementHandle.evalOnSelector(progress, params, params.expression, { isFunction: params.isFunction, world: params.world }, parseArgument(params.arg))) };
+ return { value: serializeResult(await this._elementHandle.evalOnSelector(progress, params, params.expression, params.isFunction, parseArgument(params.arg))) };
}
async evalOnSelectorAll(params: channels.ElementHandleEvalOnSelectorAllParams, progress: Progress): Promise<channels.ElementHandleEvalOnSelectorAllResult> {
- return { value: serializeResult(await this._elementHandle.evalOnSelectorAll(progress, params.selector, params.expression, { isFunction: params.isFunction, world: params.world }, parseArgument(params.arg))) };
+ return { value: serializeResult(await this._elementHandle.evalOnSelectorAll(progress, params.selector, params.expression, params.isFunction, parseArgument(params.arg))) };
}
async waitForElementState(params: channels.ElementHandleWaitForElementStateParams, progress: Progress): Promise<void> {
diff --git a/packages/playwright-core/src/server/dispatchers/frameDispatcher.ts b/packages/playwright-core/src/server/dispatchers/frameDispatcher.ts
index 6242949f5a..eee4307277 100644
--- a/packages/playwright-core/src/server/dispatchers/frameDispatcher.ts
+++ b/packages/playwright-core/src/server/dispatchers/frameDispatcher.ts
@@ -84,7 +84,7 @@ export class FrameDispatcher extends Dispatcher<Frame, channels.FrameChannel, Br
}
async evaluateExpression(params: channels.FrameEvaluateExpressionParams, progress: Progress): Promise<channels.FrameEvaluateExpressionResult> {
- return { value: serializeResult(await this._frame.evaluateExpression(progress, params.expression, { isFunction: params.isFunction, world: params.world }, parseArgument(params.arg))) };
+ return { value: serializeResult(await this._frame.evaluateExpression(progress, params.expression, { isFunction: params.isFunction }, parseArgument(params.arg))) };
}
async evaluateExpressionHandle(params: channels.FrameEvaluateExpressionHandleParams, progress: Progress): Promise<channels.FrameEvaluateExpressionHandleResult> {
@@ -100,11 +100,11 @@ export class FrameDispatcher extends Dispatcher<Frame, channels.FrameChannel, Br
}
async evalOnSelector(params: channels.FrameEvalOnSelectorParams, progress: Progress): Promise<channels.FrameEvalOnSelectorResult> {
- return { value: serializeResult(await this._frame.evalOnSelector(progress, params, params.expression, { isFunction: params.isFunction, world: params.world }, parseArgument(params.arg))) };
+ return { value: serializeResult(await this._frame.evalOnSelector(progress, params, params.expression, params.isFunction, parseArgument(params.arg))) };
}
async evalOnSelectorAll(params: channels.FrameEvalOnSelectorAllParams, progress: Progress): Promise<channels.FrameEvalOnSelectorAllResult> {
- return { value: serializeResult(await this._frame.evalOnSelectorAll(progress, params.selector, params.expression, { isFunction: params.isFunction, world: params.world }, parseArgument(params.arg))) };
+ return { value: serializeResult(await this._frame.evalOnSelectorAll(progress, params.selector, params.expression, params.isFunction, parseArgument(params.arg))) };
}
async querySelector(params: channels.FrameQuerySelectorParams, progress: Progress): Promise<channels.FrameQuerySelectorResult> {
diff --git a/packages/playwright-core/src/server/dispatchers/jsHandleDispatcher.ts b/packages/playwright-core/src/server/dispatchers/jsHandleDispatcher.ts
index c2aa99a892..d3ecc88c1b 100644
--- a/packages/playwright-core/src/server/dispatchers/jsHandleDispatcher.ts
+++ b/packages/playwright-core/src/server/dispatchers/jsHandleDispatcher.ts
@@ -43,8 +43,6 @@ export class JSHandleDispatcher<ParentScope extends JSHandleDispatcherParentScop
}
async evaluateExpression(params: channels.JSHandleEvaluateExpressionParams, progress: Progress): Promise<channels.JSHandleEvaluateExpressionResult> {
- if (params.world)
- throw new Error(`Only element handles can be evaluated in the "${params.world}" world`);
const jsHandle = await this._object.evaluateExpression(progress, params.expression, { isFunction: params.isFunction }, parseArgument(params.arg));
return { value: serializeResult(jsHandle) };
}
diff --git a/packages/playwright-core/src/server/dom.ts b/packages/playwright-core/src/server/dom.ts
index 35c364705b..2f1e43834b 100644
--- a/packages/playwright-core/src/server/dom.ts
+++ b/packages/playwright-core/src/server/dom.ts
@@ -882,21 +882,12 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
return this._frame.selectors.queryAll(selector, this);
}
- override async evaluateExpression(progress: Progress, expression: string, options: { isFunction?: boolean, world?: types.World }, arg: any): Promise<any> {
- return await progress.race(this.internalEvaluateExpression(expression, options, arg));
+ async evalOnSelector(progress: Progress, target: types.SelectorTarget, expression: string, isFunction: boolean | undefined, arg: any): Promise<any> {
+ return this._frame.evalOnSelector(progress, { ...target, scope: this }, expression, isFunction, arg);
}
- override async internalEvaluateExpression(expression: string, options: { isFunction?: boolean, world?: types.World }, arg: any): Promise<any> {
- const context = options.world ? await this._frame.context(options.world) : this._context;
- return await js.evaluateExpression(context, expression, { isFunction: options.isFunction, returnByValue: true }, this, arg);
- }
-
- async evalOnSelector(progress: Progress, target: types.SelectorTarget, expression: string, options: { isFunction?: boolean, world?: types.World }, arg: any): Promise<any> {
- return this._frame.evalOnSelector(progress, { ...target, scope: this }, expression, options, arg);
- }
-
- async evalOnSelectorAll(progress: Progress, selector: string, expression: string, options: { isFunction?: boolean, world?: types.World }, arg: any): Promise<any> {
- return this._frame.evalOnSelectorAll(progress, selector, expression, options, arg, this);
+ async evalOnSelectorAll(progress: Progress, selector: string, expression: string, isFunction: boolean | undefined, arg: any): Promise<any> {
+ return this._frame.evalOnSelectorAll(progress, selector, expression, isFunction, arg, this);
}
async isVisible(progress: Progress): Promise<boolean> {
diff --git a/packages/playwright-core/src/server/frameSelectors.ts b/packages/playwright-core/src/server/frameSelectors.ts
index e227b1799f..13ae9adc67 100644
--- a/packages/playwright-core/src/server/frameSelectors.ts
+++ b/packages/playwright-core/src/server/frameSelectors.ts
@@ -67,25 +67,13 @@ export class FrameSelectors {
return adoptIfNeeded(elementHandle, await elementHandle._frame.mainContext());
}
- async queryArrayInWorld(selector: string, world: types.World, scope?: ElementHandle): Promise<JSHandle<Element[]>> {
- const resolved = await this.callOnSelectorHandle({ selector, mainWorld: world === 'main', strict: false, scope }, ({ elements }) => elements, {});
+ async queryArrayInMainWorld(selector: string, scope?: ElementHandle): Promise<JSHandle<Element[]>> {
+ const resolved = await this.callOnSelectorHandle({ selector, mainWorld: true, strict: false, scope }, ({ elements }) => elements, {});
if (!resolved) {
- const context = await this.frame.context(world);
+ const context = await this.frame.context('main');
return await context.evaluateHandle(() => []);
}
- // Note that the selector may have been resolved in the main world regardless of the requested
- // one, e.g. when a custom selector engine requires it. Move the elements over in that case.
- const context = await resolved.frame.context(world);
- if (context === resolved.result._context)
- return resolved.result;
- const properties = await resolved.result.internalGetProperties();
- resolved.result.dispose();
- const elements = [...properties.values()];
- try {
- return await context.evaluateExpressionHandle('elements => elements', { isFunction: true }, elements);
- } finally {
- elements.map(element => element.dispose());
- }
+ return resolved.result;
}
async queryCount(selector: string): Promise<number> {
diff --git a/packages/playwright-core/src/server/frames.ts b/packages/playwright-core/src/server/frames.ts
index 3e635e85f5..5d74ae0e39 100644
--- a/packages/playwright-core/src/server/frames.ts
+++ b/packages/playwright-core/src/server/frames.ts
@@ -908,26 +908,26 @@ export class Frame extends SdkObject<FrameEventMap> {
}, { type, eventInit }, { mainWorld: true });
}
- async evalOnSelector(progress: Progress, target: types.SelectorTarget, expression: string, options: { isFunction?: boolean, world?: types.World }, arg: any): Promise<any> {
- return progress.race(this._evalOnSelector(target, expression, options, arg));
+ async evalOnSelector(progress: Progress, target: types.SelectorTarget, expression: string, isFunction: boolean | undefined, arg: any): Promise<any> {
+ return progress.race(this._evalOnSelector(target, expression, isFunction, arg));
}
- private async _evalOnSelector(target: types.SelectorTarget, expression: string, options: { isFunction?: boolean, world?: types.World }, arg: any): Promise<any> {
+ private async _evalOnSelector(target: types.SelectorTarget, expression: string, isFunction: boolean | undefined, arg: any): Promise<any> {
const handle = await this.selectors.query(target);
if (!handle)
throw new Error(`Failed to find element matching selector "${target.selector}"`);
- const result = await handle.internalEvaluateExpression(expression, options, arg);
+ const result = await handle.internalEvaluateExpression(expression, { isFunction }, arg);
handle.dispose();
return result;
}
- async evalOnSelectorAll(progress: Progress, selector: string, expression: string, options: { isFunction?: boolean, world?: types.World }, arg: any, scope?: dom.ElementHandle): Promise<any> {
- return progress.race(this._evalOnSelectorAll(selector, expression, options, arg, scope));
+ async evalOnSelectorAll(progress: Progress, selector: string, expression: string, isFunction: boolean | undefined, arg: any, scope?: dom.ElementHandle): Promise<any> {
+ return progress.race(this._evalOnSelectorAll(selector, expression, isFunction, arg, scope));
}
- private async _evalOnSelectorAll(selector: string, expression: string, options: { isFunction?: boolean, world?: types.World }, arg: any, scope?: dom.ElementHandle): Promise<any> {
- const arrayHandle = await this.selectors.queryArrayInWorld(selector, options.world ?? 'main', scope);
- const result = await arrayHandle.internalEvaluateExpression(expression, { isFunction: options.isFunction }, arg);
+ private async _evalOnSelectorAll(selector: string, expression: string, isFunction: boolean | undefined, arg: any, scope?: dom.ElementHandle): Promise<any> {
+ const arrayHandle = await this.selectors.queryArrayInMainWorld(selector, scope);
+ const result = await arrayHandle.internalEvaluateExpression(expression, { isFunction }, arg);
arrayHandle.dispose();
return result;
}
diff --git a/packages/playwright-core/types/types.d.ts b/packages/playwright-core/types/types.d.ts
index 8ba8d80428..7813b47719 100644
--- a/packages/playwright-core/types/types.d.ts
+++ b/packages/playwright-core/types/types.d.ts
@@ -134,7 +134,7 @@ export interface Page {
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-evaluate-option-expression).
* @param options
*/
- evaluate<R, Arg>(pageFunction: PageFunction<Arg, R>, arg: Arg, options?: { exposeFunctions?: boolean, world?: 'main'|'utility' }): Promise<R>;
+ evaluate<R, Arg>(pageFunction: PageFunction<Arg, R>, arg: Arg, options?: { exposeFunctions?: boolean }): Promise<R>;
/**
* Returns the value of the
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-evaluate-option-expression) invocation.
@@ -187,7 +187,7 @@ export interface Page {
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-evaluate-option-expression).
* @param options
*/
- evaluate<R>(pageFunction: PageFunction<void, R>, arg?: any, options?: { exposeFunctions?: boolean, world?: 'main'|'utility' }): Promise<R>;
+ evaluate<R>(pageFunction: PageFunction<void, R>, arg?: any, options?: { exposeFunctions?: boolean }): Promise<R>;
/**
* Returns the value of the
@@ -400,7 +400,7 @@ export interface Page {
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-option-expression).
* @param options
*/
- $eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], Arg, R>, arg: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], Arg, R>, arg: Arg): Promise<R>;
/**
* **NOTE** This method does not wait for the element to pass actionability checks and therefore can lead to the flaky tests.
* Use
@@ -433,7 +433,7 @@ export interface Page {
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-option-expression).
* @param options
*/
- $eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, Arg, R>, arg: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, Arg, R>, arg: Arg): Promise<R>;
/**
* **NOTE** This method does not wait for the element to pass actionability checks and therefore can lead to the flaky tests.
* Use
@@ -466,7 +466,7 @@ export interface Page {
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-option-expression).
* @param options
*/
- $eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], void, R>, arg?: any, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], void, R>, arg?: any): Promise<R>;
/**
* **NOTE** This method does not wait for the element to pass actionability checks and therefore can lead to the flaky tests.
* Use
@@ -499,11 +499,11 @@ export interface Page {
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-option-expression).
* @param options
*/
- $eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, void, R>, arg?: any, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, void, R>, arg?: any): Promise<R>;
/**
* **NOTE** In most cases,
- * [locator.evaluateAll(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
+ * [locator.evaluateAll(pageFunction[, arg])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
* other [Locator](https://playwright.dev/docs/api/class-locator) helper methods and web-first assertions do a better
* job.
*
@@ -516,7 +516,7 @@ export interface Page {
*
* If [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all-option-expression) returns
* a [Promise], then
- * [page.$$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all)
+ * [page.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all)
* would wait for the promise to resolve and return its value.
*
* **Usage**
@@ -529,12 +529,11 @@ export interface Page {
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all-option-expression).
- * @param options
*/
- $$eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], Arg, R>, arg: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $$eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], Arg, R>, arg: Arg): Promise<R>;
/**
* **NOTE** In most cases,
- * [locator.evaluateAll(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
+ * [locator.evaluateAll(pageFunction[, arg])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
* other [Locator](https://playwright.dev/docs/api/class-locator) helper methods and web-first assertions do a better
* job.
*
@@ -547,7 +546,7 @@ export interface Page {
*
* If [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all-option-expression) returns
* a [Promise], then
- * [page.$$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all)
+ * [page.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all)
* would wait for the promise to resolve and return its value.
*
* **Usage**
@@ -560,12 +559,11 @@ export interface Page {
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all-option-expression).
- * @param options
*/
- $$eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], Arg, R>, arg: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $$eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], Arg, R>, arg: Arg): Promise<R>;
/**
* **NOTE** In most cases,
- * [locator.evaluateAll(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
+ * [locator.evaluateAll(pageFunction[, arg])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
* other [Locator](https://playwright.dev/docs/api/class-locator) helper methods and web-first assertions do a better
* job.
*
@@ -578,7 +576,7 @@ export interface Page {
*
* If [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all-option-expression) returns
* a [Promise], then
- * [page.$$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all)
+ * [page.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all)
* would wait for the promise to resolve and return its value.
*
* **Usage**
@@ -591,12 +589,11 @@ export interface Page {
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all-option-expression).
- * @param options
*/
- $$eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], void, R>, arg?: any, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $$eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], void, R>, arg?: any): Promise<R>;
/**
* **NOTE** In most cases,
- * [locator.evaluateAll(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
+ * [locator.evaluateAll(pageFunction[, arg])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
* other [Locator](https://playwright.dev/docs/api/class-locator) helper methods and web-first assertions do a better
* job.
*
@@ -609,7 +606,7 @@ export interface Page {
*
* If [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all-option-expression) returns
* a [Promise], then
- * [page.$$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all)
+ * [page.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all)
* would wait for the promise to resolve and return its value.
*
* **Usage**
@@ -622,9 +619,8 @@ export interface Page {
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all-option-expression).
- * @param options
*/
- $$eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], void, R>, arg?: any, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $$eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], void, R>, arg?: any): Promise<R>;
/**
* Returns when the
@@ -5988,7 +5984,7 @@ export interface Frame {
* [`pageFunction`](https://playwright.dev/docs/api/class-frame#frame-evaluate-option-expression).
* @param options
*/
- evaluate<R, Arg>(pageFunction: PageFunction<Arg, R>, arg: Arg, options?: { exposeFunctions?: boolean, world?: 'main'|'utility' }): Promise<R>;
+ evaluate<R, Arg>(pageFunction: PageFunction<Arg, R>, arg: Arg, options?: { exposeFunctions?: boolean }): Promise<R>;
/**
* Returns the return value of
* [`pageFunction`](https://playwright.dev/docs/api/class-frame#frame-evaluate-option-expression).
@@ -6037,7 +6033,7 @@ export interface Frame {
* [`pageFunction`](https://playwright.dev/docs/api/class-frame#frame-evaluate-option-expression).
* @param options
*/
- evaluate<R>(pageFunction: PageFunction<void, R>, arg?: any, options?: { exposeFunctions?: boolean, world?: 'main'|'utility' }): Promise<R>;
+ evaluate<R>(pageFunction: PageFunction<void, R>, arg?: any, options?: { exposeFunctions?: boolean }): Promise<R>;
/**
* Returns the return value of
@@ -6230,7 +6226,7 @@ export interface Frame {
* [`pageFunction`](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-option-expression).
* @param options
*/
- $eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], Arg, R>, arg: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], Arg, R>, arg: Arg): Promise<R>;
/**
* **NOTE** This method does not wait for the element to pass the actionability checks and therefore can lead to the flaky
* tests. Use
@@ -6263,7 +6259,7 @@ export interface Frame {
* [`pageFunction`](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-option-expression).
* @param options
*/
- $eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, Arg, R>, arg: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, Arg, R>, arg: Arg): Promise<R>;
/**
* **NOTE** This method does not wait for the element to pass the actionability checks and therefore can lead to the flaky
* tests. Use
@@ -6296,7 +6292,7 @@ export interface Frame {
* [`pageFunction`](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-option-expression).
* @param options
*/
- $eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], void, R>, arg?: any, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], void, R>, arg?: any): Promise<R>;
/**
* **NOTE** This method does not wait for the element to pass the actionability checks and therefore can lead to the flaky
* tests. Use
@@ -6329,11 +6325,11 @@ export interface Frame {
* [`pageFunction`](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-option-expression).
* @param options
*/
- $eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, void, R>, arg?: any, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, void, R>, arg?: any): Promise<R>;
/**
* **NOTE** In most cases,
- * [locator.evaluateAll(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
+ * [locator.evaluateAll(pageFunction[, arg])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
* other [Locator](https://playwright.dev/docs/api/class-locator) helper methods and web-first assertions do a better
* job.
*
@@ -6346,7 +6342,7 @@ export interface Frame {
*
* If [`pageFunction`](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-all-option-expression)
* returns a [Promise], then
- * [frame.$$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-all)
+ * [frame.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-all)
* would wait for the promise to resolve and return its value.
*
* **Usage**
@@ -6359,12 +6355,11 @@ export interface Frame {
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-all-option-expression).
- * @param options
*/
- $$eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], Arg, R>, arg: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $$eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], Arg, R>, arg: Arg): Promise<R>;
/**
* **NOTE** In most cases,
- * [locator.evaluateAll(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
+ * [locator.evaluateAll(pageFunction[, arg])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
* other [Locator](https://playwright.dev/docs/api/class-locator) helper methods and web-first assertions do a better
* job.
*
@@ -6377,7 +6372,7 @@ export interface Frame {
*
* If [`pageFunction`](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-all-option-expression)
* returns a [Promise], then
- * [frame.$$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-all)
+ * [frame.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-all)
* would wait for the promise to resolve and return its value.
*
* **Usage**
@@ -6390,12 +6385,11 @@ export interface Frame {
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-all-option-expression).
- * @param options
*/
- $$eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], Arg, R>, arg: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $$eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], Arg, R>, arg: Arg): Promise<R>;
/**
* **NOTE** In most cases,
- * [locator.evaluateAll(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
+ * [locator.evaluateAll(pageFunction[, arg])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
* other [Locator](https://playwright.dev/docs/api/class-locator) helper methods and web-first assertions do a better
* job.
*
@@ -6408,7 +6402,7 @@ export interface Frame {
*
* If [`pageFunction`](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-all-option-expression)
* returns a [Promise], then
- * [frame.$$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-all)
+ * [frame.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-all)
* would wait for the promise to resolve and return its value.
*
* **Usage**
@@ -6421,12 +6415,11 @@ export interface Frame {
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-all-option-expression).
- * @param options
*/
- $$eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], void, R>, arg?: any, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $$eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], void, R>, arg?: any): Promise<R>;
/**
* **NOTE** In most cases,
- * [locator.evaluateAll(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
+ * [locator.evaluateAll(pageFunction[, arg])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
* other [Locator](https://playwright.dev/docs/api/class-locator) helper methods and web-first assertions do a better
* job.
*
@@ -6439,7 +6432,7 @@ export interface Frame {
*
* If [`pageFunction`](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-all-option-expression)
* returns a [Promise], then
- * [frame.$$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-all)
+ * [frame.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-all)
* would wait for the promise to resolve and return its value.
*
* **Usage**
@@ -6452,9 +6445,8 @@ export interface Frame {
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-all-option-expression).
- * @param options
*/
- $$eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], void, R>, arg?: any, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $$eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], void, R>, arg?: any): Promise<R>;
/**
* Returns when the
@@ -12500,7 +12492,7 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
* If
* [`pageFunction`](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-option-expression)
* returns a [Promise], then
- * [elementHandle.$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector)
+ * [elementHandle.$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector)
* would wait for the promise to resolve and return its value.
*
* **Usage**
@@ -12515,9 +12507,8 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-option-expression).
- * @param options
*/
- $eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], Arg, R>, arg: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], Arg, R>, arg: Arg): Promise<R>;
/**
* **NOTE** This method does not wait for the element to pass actionability checks and therefore can lead to the flaky tests.
* Use
@@ -12535,7 +12526,7 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
* If
* [`pageFunction`](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-option-expression)
* returns a [Promise], then
- * [elementHandle.$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector)
+ * [elementHandle.$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector)
* would wait for the promise to resolve and return its value.
*
* **Usage**
@@ -12550,9 +12541,8 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-option-expression).
- * @param options
*/
- $eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, Arg, R>, arg: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, Arg, R>, arg: Arg): Promise<R>;
/**
* **NOTE** This method does not wait for the element to pass actionability checks and therefore can lead to the flaky tests.
* Use
@@ -12570,7 +12560,7 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
* If
* [`pageFunction`](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-option-expression)
* returns a [Promise], then
- * [elementHandle.$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector)
+ * [elementHandle.$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector)
* would wait for the promise to resolve and return its value.
*
* **Usage**
@@ -12585,9 +12575,8 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-option-expression).
- * @param options
*/
- $eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], void, R>, arg?: any, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], void, R>, arg?: any): Promise<R>;
/**
* **NOTE** This method does not wait for the element to pass actionability checks and therefore can lead to the flaky tests.
* Use
@@ -12605,7 +12594,7 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
* If
* [`pageFunction`](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-option-expression)
* returns a [Promise], then
- * [elementHandle.$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector)
+ * [elementHandle.$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector)
* would wait for the promise to resolve and return its value.
*
* **Usage**
@@ -12620,13 +12609,12 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-option-expression).
- * @param options
*/
- $eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, void, R>, arg?: any, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, void, R>, arg?: any): Promise<R>;
/**
* **NOTE** In most cases,
- * [locator.evaluateAll(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
+ * [locator.evaluateAll(pageFunction[, arg])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
* other [Locator](https://playwright.dev/docs/api/class-locator) helper methods and web-first assertions do a better
* job.
*
@@ -12640,7 +12628,7 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
* If
* [`pageFunction`](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-all-option-expression)
* returns a [Promise], then
- * [elementHandle.$$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-all)
+ * [elementHandle.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-all)
* would wait for the promise to resolve and return its value.
*
* **Usage**
@@ -12663,12 +12651,11 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-all-option-expression).
- * @param options
*/
- $$eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], Arg, R>, arg: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $$eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], Arg, R>, arg: Arg): Promise<R>;
/**
* **NOTE** In most cases,
- * [locator.evaluateAll(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
+ * [locator.evaluateAll(pageFunction[, arg])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
* other [Locator](https://playwright.dev/docs/api/class-locator) helper methods and web-first assertions do a better
* job.
*
@@ -12682,7 +12669,7 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
* If
* [`pageFunction`](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-all-option-expression)
* returns a [Promise], then
- * [elementHandle.$$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-all)
+ * [elementHandle.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-all)
* would wait for the promise to resolve and return its value.
*
* **Usage**
@@ -12705,12 +12692,11 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-all-option-expression).
- * @param options
*/
- $$eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], Arg, R>, arg: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $$eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], Arg, R>, arg: Arg): Promise<R>;
/**
* **NOTE** In most cases,
- * [locator.evaluateAll(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
+ * [locator.evaluateAll(pageFunction[, arg])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
* other [Locator](https://playwright.dev/docs/api/class-locator) helper methods and web-first assertions do a better
* job.
*
@@ -12724,7 +12710,7 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
* If
* [`pageFunction`](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-all-option-expression)
* returns a [Promise], then
- * [elementHandle.$$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-all)
+ * [elementHandle.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-all)
* would wait for the promise to resolve and return its value.
*
* **Usage**
@@ -12747,12 +12733,11 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-all-option-expression).
- * @param options
*/
- $$eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], void, R>, arg?: any, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $$eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], void, R>, arg?: any): Promise<R>;
/**
* **NOTE** In most cases,
- * [locator.evaluateAll(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
+ * [locator.evaluateAll(pageFunction[, arg])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
* other [Locator](https://playwright.dev/docs/api/class-locator) helper methods and web-first assertions do a better
* job.
*
@@ -12766,7 +12751,7 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
* If
* [`pageFunction`](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-all-option-expression)
* returns a [Promise], then
- * [elementHandle.$$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-all)
+ * [elementHandle.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-all)
* would wait for the promise to resolve and return its value.
*
* **Usage**
@@ -12789,9 +12774,8 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-all-option-expression).
- * @param options
*/
- $$eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], void, R>, arg?: any, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $$eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], void, R>, arg?: any): Promise<R>;
/**
* **NOTE** Use web assertions that assert visibility or a locator-based
@@ -14366,7 +14350,7 @@ export interface Locator {
* [`pageFunction`](https://playwright.dev/docs/api/class-locator#locator-evaluate-option-expression).
* @param options
*/
- evaluate<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(pageFunction: PageFunctionOn<E, Arg, R>, arg?: Arg, options?: { timeout?: number, signal?: AbortSignal, exposeFunctions?: boolean, world?: 'main'|'utility' }): Promise<R>;
+ evaluate<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(pageFunction: PageFunctionOn<E, Arg, R>, arg?: Arg, options?: { timeout?: number, signal?: AbortSignal, exposeFunctions?: boolean }): Promise<R>;
/**
* Execute JavaScript code in the page, taking the matching element as an argument, and return a
* [JSHandle](https://playwright.dev/docs/api/class-jshandle) with the result.
@@ -14427,9 +14411,8 @@ export interface Locator {
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-locator#locator-evaluate-all-option-expression).
- * @param options
*/
- evaluateAll<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(pageFunction: PageFunctionOn<E[], Arg, R>, arg?: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
+ evaluateAll<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(pageFunction: PageFunctionOn<E[], Arg, R>, arg?: Arg): Promise<R>;
/**
* Returns when
* [`pageFunction`](https://playwright.dev/docs/api/class-locator#locator-wait-for-function-option-expression) returns
diff --git a/packages/protocol/spec/frame.yml b/packages/protocol/spec/frame.yml
index dfac57e523..d3934e4914 100644
--- a/packages/protocol/spec/frame.yml
+++ b/packages/protocol/spec/frame.yml
@@ -34,11 +34,6 @@ Frame:
expression: string
isFunction: boolean?
arg: SerializedArgument
- world:
- type: enum?
- literals:
- - main
- - utility
returns:
value: SerializedValue
flags:
@@ -53,11 +48,6 @@ Frame:
expression: string
isFunction: boolean?
arg: SerializedArgument
- world:
- type: enum?
- literals:
- - main
- - utility
returns:
value: SerializedValue
flags:
@@ -339,11 +329,6 @@ Frame:
expression: string
isFunction: boolean?
arg: SerializedArgument
- world:
- type: enum?
- literals:
- - main
- - utility
returns:
value: SerializedValue
flags:
diff --git a/packages/protocol/spec/handles.yml b/packages/protocol/spec/handles.yml
index 00e581fe65..9a358546f7 100644
--- a/packages/protocol/spec/handles.yml
+++ b/packages/protocol/spec/handles.yml
@@ -29,11 +29,6 @@ JSHandle:
expression: string
isFunction: boolean?
arg: SerializedArgument
- world:
- type: enum?
- literals:
- - main
- - utility
returns:
value: SerializedValue
flags:
@@ -100,11 +95,6 @@ ElementHandle:
expression: string
isFunction: boolean?
arg: SerializedArgument
- world:
- type: enum?
- literals:
- - main
- - utility
returns:
value: SerializedValue
flags:
@@ -119,11 +109,6 @@ ElementHandle:
expression: string
isFunction: boolean?
arg: SerializedArgument
- world:
- type: enum?
- literals:
- - main
- - utility
returns:
value: SerializedValue
flags:
diff --git a/packages/protocol/src/validator.ts b/packages/protocol/src/validator.ts
index 9cc85050d8..8df2d2e6e0 100644
--- a/packages/protocol/src/validator.ts
+++ b/packages/protocol/src/validator.ts
@@ -1267,7 +1267,6 @@ scheme.FrameEvalOnSelectorParams = tObject({
expression: tString,
isFunction: tOptional(tBoolean),
arg: tType('SerializedArgument'),
- world: tOptional(tEnum(['main', 'utility'])),
});
scheme.FrameEvalOnSelectorResult = tObject({
value: tType('SerializedValue'),
@@ -1277,7 +1276,6 @@ scheme.FrameEvalOnSelectorAllParams = tObject({
expression: tString,
isFunction: tOptional(tBoolean),
arg: tType('SerializedArgument'),
- world: tOptional(tEnum(['main', 'utility'])),
});
scheme.FrameEvalOnSelectorAllResult = tObject({
value: tType('SerializedValue'),
@@ -1403,7 +1401,6 @@ scheme.FrameEvaluateExpressionParams = tObject({
expression: tString,
isFunction: tOptional(tBoolean),
arg: tType('SerializedArgument'),
- world: tOptional(tEnum(['main', 'utility'])),
});
scheme.FrameEvaluateExpressionResult = tObject({
value: tType('SerializedValue'),
@@ -1717,7 +1714,6 @@ scheme.JSHandleEvaluateExpressionParams = tObject({
expression: tString,
isFunction: tOptional(tBoolean),
arg: tType('SerializedArgument'),
- world: tOptional(tEnum(['main', 'utility'])),
});
scheme.ElementHandleEvaluateExpressionParams = tType('JSHandleEvaluateExpressionParams');
scheme.JSHandleEvaluateExpressionResult = tObject({
@@ -1766,7 +1762,6 @@ scheme.ElementHandleEvalOnSelectorParams = tObject({
expression: tString,
isFunction: tOptional(tBoolean),
arg: tType('SerializedArgument'),
- world: tOptional(tEnum(['main', 'utility'])),
});
scheme.ElementHandleEvalOnSelectorResult = tObject({
value: tType('SerializedValue'),
@@ -1776,7 +1771,6 @@ scheme.ElementHandleEvalOnSelectorAllParams = tObject({
expression: tString,
isFunction: tOptional(tBoolean),
arg: tType('SerializedArgument'),
- world: tOptional(tEnum(['main', 'utility'])),
});
scheme.ElementHandleEvalOnSelectorAllResult = tObject({
value: tType('SerializedValue'),
diff --git a/tests/library/selectors-register.spec.ts b/tests/library/selectors-register.spec.ts
index 4a68753ac3..b739376186 100644
--- a/tests/library/selectors-register.spec.ts
+++ b/tests/library/selectors-register.spec.ts
@@ -52,27 +52,6 @@ it('should work', async ({ playwright, browser }) => {
await context.close();
});
-it('should support the world option with a main world selector engine', async ({ playwright, browser }) => {
- // Custom engines without "contentScript" resolve in the main world, but the
- // evaluated function should still run in the requested world.
- await playwright.selectors.register('world-tag', `(${createTagSelector.toString()})()`);
-
- const context = await browser.newContext();
- const page = await context.newPage();
- await page.setContent('<div id=one>one</div><div id=two>two</div>');
- await page.evaluate(() => (window as any).marker = 'main');
-
- expect(await page.$eval('world-tag=DIV', e => (window as any).marker)).toBe('main');
- expect(await page.$eval('world-tag=DIV', e => (window as any).marker, undefined, { world: 'utility' })).toBe(undefined);
- expect(await page.$eval('world-tag=DIV', e => e.id, undefined, { world: 'utility' })).toBe('one');
-
- expect(await page.$$eval('world-tag=DIV', ee => (window as any).marker)).toBe('main');
- expect(await page.$$eval('world-tag=DIV', ee => (window as any).marker, undefined, { world: 'utility' })).toBe(undefined);
- expect(await page.$$eval('world-tag=DIV', ee => ee.map(e => e.id), undefined, { world: 'utility' })).toEqual(['one', 'two']);
-
- await context.close();
-});
-
it('should work when registered on global', async ({ browser, mode }) => {
it.skip(mode === 'driver', 'We expect registering selectors on the right Playwright instance.');
diff --git a/tests/page/page-evaluate-world.spec.ts b/tests/page/page-evaluate-world.spec.ts
deleted file mode 100644
index ed64695935..0000000000
--- a/tests/page/page-evaluate-world.spec.ts
+++ /dev/null
@@ -1,150 +0,0 @@
-/**
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import { attachFrame } from '../config/utils';
-import { test as it, expect } from './pageTest';
-
-it('should evaluate in different worlds', async ({ page }) => {
- await page.evaluate(() => (window as any).marker = 'main');
- await page.evaluate(() => (window as any).marker = 'utility', undefined, { world: 'utility' });
- expect(await page.evaluate(() => (window as any).marker)).toBe('main');
- expect(await page.evaluate(() => (window as any).marker, undefined, { world: 'main' })).toBe('main');
- expect(await page.evaluate(() => (window as any).marker, undefined, { world: 'utility' })).toBe('utility');
-});
-
-it('should share the dom between worlds', async ({ page }) => {
- await page.setContent(`
- <div id=parent>
- <div class=child data-value=1>one</div>
- <div class=child data-value=2>two</div>
- </div>
- `);
- await page.evaluate(() => document.querySelector('.child')!.setAttribute('data-from-main', 'yes'));
- await page.evaluate(() => document.querySelector('.child')!.setAttribute('data-from-utility', 'yes'), undefined, { world: 'utility' });
- for (const world of ['main', 'utility'] as const) {
- const attributes = await page.evaluate(() => {
- const child = document.querySelector('.child')!;
- return {
- value: child.getAttribute('data-value'),
- fromMain: child.getAttribute('data-from-main'),
- fromUtility: child.getAttribute('data-from-utility'),
- text: child.textContent,
- };
- }, undefined, { world });
- expect(attributes).toEqual({ value: '1', fromMain: 'yes', fromUtility: 'yes', text: 'one' });
- }
-});
-
-it('should evaluate in different worlds in a frame', async ({ page, server }) => {
- await page.goto(server.EMPTY_PAGE);
- const frame = await attachFrame(page, 'frame1', server.EMPTY_PAGE + '?frame');
- await frame.evaluate(() => (window as any).marker = 'main');
- expect(await frame.evaluate(() => (window as any).marker, undefined, { world: 'main' })).toBe('main');
- expect(await frame.evaluate(() => (window as any).marker, undefined, { world: 'utility' })).toBe(undefined);
- // Worlds are per-frame, so the main frame is not affected.
- expect(await page.evaluate(() => (window as any).marker)).toBe(undefined);
- expect(await frame.evaluate(() => location.search, undefined, { world: 'utility' })).toBe('?frame');
-});
-
-it('should evaluate locator in different worlds', async ({ page }) => {
- await page.setContent(`
- <div id=parent>
- <div class=child data-value=1>one</div>
- <div class=child data-value=2>two</div>
- </div>
- `);
- await page.evaluate(() => (window as any).marker = 'main');
- const locator = page.locator('.child').first();
- expect(await locator.evaluate(e => (window as any).marker)).toBe('main');
- expect(await locator.evaluate(e => (window as any).marker, undefined, { world: 'utility' })).toBe(undefined);
- // The element is the same in both worlds.
- for (const world of ['main', 'utility'] as const)
- expect(await locator.evaluate(e => e.getAttribute('data-value') + '/' + e.textContent, undefined, { world })).toBe('1/one');
-});
-
-it('should evaluate all in different worlds', async ({ page }) => {
- await page.setContent(`
- <div id=parent>
- <div class=child data-value=1>one</div>
- <div class=child data-value=2>two</div>
- </div>
- `);
- await page.evaluate(() => (window as any).marker = 'main');
- const locator = page.locator('.child');
- expect(await locator.evaluateAll(ee => (window as any).marker)).toBe('main');
- expect(await locator.evaluateAll(ee => (window as any).marker, undefined, { world: 'utility' })).toBe(undefined);
- // The elements are the same in both worlds.
- for (const world of ['main', 'utility'] as const)
- expect(await locator.evaluateAll(ee => ee.map(e => e.getAttribute('data-value') + '/' + e.textContent), undefined, { world })).toEqual(['1/one', '2/two']);
-});
-
-it('should eval on selector in different worlds', async ({ page }) => {
- await page.setContent(`
- <div id=parent>
- <div class=child data-value=1>one</div>
- <div class=child data-value=2>two</div>
- </div>
- `);
- await page.evaluate(() => (window as any).marker = 'main');
- expect(await page.$eval('.child', e => (window as any).marker)).toBe('main');
- expect(await page.$eval('.child', e => (window as any).marker, undefined, { world: 'utility' })).toBe(undefined);
- expect(await page.$$eval('.child', ee => (window as any).marker)).toBe('main');
- expect(await page.$$eval('.child', ee => (window as any).marker, undefined, { world: 'utility' })).toBe(undefined);
- for (const world of ['main', 'utility'] as const) {
- expect(await page.$eval('.child', e => e.getAttribute('data-value'), undefined, { world })).toBe('1');
- expect(await page.$$eval('.child', ee => ee.map(e => e.textContent), undefined, { world })).toEqual(['one', 'two']);
- }
-});
-
-it('should eval on selector inside an element handle in different worlds', async ({ page }) => {
- await page.setContent(`
- <div id=parent>
- <div class=child data-value=1>one</div>
- <div class=child data-value=2>two</div>
- </div>
- `);
- await page.evaluate(() => (window as any).marker = 'main');
- const parent = (await page.$('#parent'))!;
- expect(await parent.$eval('.child', e => (window as any).marker)).toBe('main');
- expect(await parent.$eval('.child', e => (window as any).marker, undefined, { world: 'utility' })).toBe(undefined);
- expect(await parent.$$eval('.child', ee => (window as any).marker)).toBe('main');
- expect(await parent.$$eval('.child', ee => (window as any).marker, undefined, { world: 'utility' })).toBe(undefined);
- for (const world of ['main', 'utility'] as const) {
- expect(await parent.$eval('.child', e => e.getAttribute('data-value'), undefined, { world })).toBe('1');
- expect(await parent.$$eval('.child', ee => ee.map(e => e.textContent), undefined, { world })).toEqual(['one', 'two']);
- }
-});
-
-it('should isolate the utility world from main world tampering', async ({ page }) => {
- await page.setContent(`
- <div id=parent>
- <div class=child data-value=1>one</div>
- <div class=child data-value=2>two</div>
- </div>
- `);
- await page.evaluate(() => {
- Element.prototype.getAttribute = () => 'tampered';
- });
- const locator = page.locator('.child').first();
- expect(await locator.evaluate(e => e.getAttribute('data-value'))).toBe('tampered');
- expect(await locator.evaluate(e => e.getAttribute('data-value'), undefined, { world: 'utility' })).toBe('1');
-});
-
-it('should reject exposeFunctions in the utility world', async ({ page }) => {
- const error = await page.evaluate(async ({ cb }) => await cb(17), { cb: (x: number) => x * 2 }, { exposeFunctions: true, world: 'utility' }).catch(e => e);
- expect(error.message).toContain('Option "exposeFunctions" is not supported in the "utility" world.');
- expect(await page.evaluate(async ({ cb }) => await cb(17), { cb: (x: number) => x * 2 }, { exposeFunctions: true, world: 'main' })).toBe(34);
-});
diff --git a/utils/generate_types/overrides.d.ts b/utils/generate_types/overrides.d.ts
index ebde294dff..7f802f637a 100644
--- a/utils/generate_types/overrides.d.ts
+++ b/utils/generate_types/overrides.d.ts
@@ -38,8 +38,8 @@ type ZodSchema = ZodTypeAny | z3.ZodTypeAny;
type InferZodSchema<T extends ZodSchema> = T extends z3.ZodTypeAny ? z3.infer<T> : T extends ZodTypeAny ? z.infer<T> : never;
export interface Page {
- evaluate<R, Arg>(pageFunction: PageFunction<Arg, R>, arg: Arg, options?: { exposeFunctions?: boolean, world?: 'main'|'utility' }): Promise<R>;
- evaluate<R>(pageFunction: PageFunction<void, R>, arg?: any, options?: { exposeFunctions?: boolean, world?: 'main'|'utility' }): Promise<R>;
+ evaluate<R, Arg>(pageFunction: PageFunction<Arg, R>, arg: Arg, options?: { exposeFunctions?: boolean }): Promise<R>;
+ evaluate<R>(pageFunction: PageFunction<void, R>, arg?: any, options?: { exposeFunctions?: boolean }): Promise<R>;
evaluateHandle<R, Arg>(pageFunction: PageFunction<Arg, R>, arg: Arg, options?: { exposeFunctions?: boolean }): Promise<SmartHandle<R>>;
evaluateHandle<R>(pageFunction: PageFunction<void, R>, arg?: any, options?: { exposeFunctions?: boolean }): Promise<SmartHandle<R>>;
@@ -52,15 +52,15 @@ export interface Page {
$$<K extends keyof HTMLElementTagNameMap>(selector: K): Promise<ElementHandleForTag<K>[]>;
$$(selector: string): Promise<ElementHandle<SVGElement | HTMLElement>[]>;
- $eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], Arg, R>, arg: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
- $eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, Arg, R>, arg: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
- $eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], void, R>, arg?: any, options?: { world?: 'main'|'utility' }): Promise<R>;
- $eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, void, R>, arg?: any, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], Arg, R>, arg: Arg): Promise<R>;
+ $eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, Arg, R>, arg: Arg): Promise<R>;
+ $eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], void, R>, arg?: any): Promise<R>;
+ $eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, void, R>, arg?: any): Promise<R>;
- $$eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], Arg, R>, arg: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
- $$eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], Arg, R>, arg: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
- $$eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], void, R>, arg?: any, options?: { world?: 'main'|'utility' }): Promise<R>;
- $$eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], void, R>, arg?: any, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $$eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], Arg, R>, arg: Arg): Promise<R>;
+ $$eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], Arg, R>, arg: Arg): Promise<R>;
+ $$eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], void, R>, arg?: any): Promise<R>;
+ $$eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], void, R>, arg?: any): Promise<R>;
waitForFunction<R, Arg>(pageFunction: PageFunction<Arg, R>, arg: Arg, options?: PageWaitForFunctionOptions): Promise<SmartHandle<R>>;
waitForFunction<R>(pageFunction: PageFunction<void, R>, arg?: any, options?: PageWaitForFunctionOptions): Promise<SmartHandle<R>>;
@@ -85,8 +85,8 @@ export interface Page {
}
export interface Frame {
- evaluate<R, Arg>(pageFunction: PageFunction<Arg, R>, arg: Arg, options?: { exposeFunctions?: boolean, world?: 'main'|'utility' }): Promise<R>;
- evaluate<R>(pageFunction: PageFunction<void, R>, arg?: any, options?: { exposeFunctions?: boolean, world?: 'main'|'utility' }): Promise<R>;
+ evaluate<R, Arg>(pageFunction: PageFunction<Arg, R>, arg: Arg, options?: { exposeFunctions?: boolean }): Promise<R>;
+ evaluate<R>(pageFunction: PageFunction<void, R>, arg?: any, options?: { exposeFunctions?: boolean }): Promise<R>;
evaluateHandle<R, Arg>(pageFunction: PageFunction<Arg, R>, arg: Arg, options?: { exposeFunctions?: boolean }): Promise<SmartHandle<R>>;
evaluateHandle<R>(pageFunction: PageFunction<void, R>, arg?: any, options?: { exposeFunctions?: boolean }): Promise<SmartHandle<R>>;
@@ -97,15 +97,15 @@ export interface Frame {
$$<K extends keyof HTMLElementTagNameMap>(selector: K): Promise<ElementHandleForTag<K>[]>;
$$(selector: string): Promise<ElementHandle<SVGElement | HTMLElement>[]>;
- $eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], Arg, R>, arg: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
- $eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, Arg, R>, arg: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
- $eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], void, R>, arg?: any, options?: { world?: 'main'|'utility' }): Promise<R>;
- $eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, void, R>, arg?: any, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], Arg, R>, arg: Arg): Promise<R>;
+ $eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, Arg, R>, arg: Arg): Promise<R>;
+ $eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], void, R>, arg?: any): Promise<R>;
+ $eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, void, R>, arg?: any): Promise<R>;
- $$eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], Arg, R>, arg: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
- $$eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], Arg, R>, arg: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
- $$eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], void, R>, arg?: any, options?: { world?: 'main'|'utility' }): Promise<R>;
- $$eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], void, R>, arg?: any, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $$eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], Arg, R>, arg: Arg): Promise<R>;
+ $$eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], Arg, R>, arg: Arg): Promise<R>;
+ $$eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], void, R>, arg?: any): Promise<R>;
+ $$eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], void, R>, arg?: any): Promise<R>;
waitForFunction<R, Arg>(pageFunction: PageFunction<Arg, R>, arg: Arg, options?: PageWaitForFunctionOptions): Promise<SmartHandle<R>>;
waitForFunction<R>(pageFunction: PageFunction<void, R>, arg?: any, options?: PageWaitForFunctionOptions): Promise<SmartHandle<R>>;
@@ -177,15 +177,15 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
$$<K extends keyof HTMLElementTagNameMap>(selector: K): Promise<ElementHandleForTag<K>[]>;
$$(selector: string): Promise<ElementHandle<SVGElement | HTMLElement>[]>;
- $eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], Arg, R>, arg: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
- $eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, Arg, R>, arg: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
- $eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], void, R>, arg?: any, options?: { world?: 'main'|'utility' }): Promise<R>;
- $eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, void, R>, arg?: any, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], Arg, R>, arg: Arg): Promise<R>;
+ $eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, Arg, R>, arg: Arg): Promise<R>;
+ $eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], void, R>, arg?: any): Promise<R>;
+ $eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, void, R>, arg?: any): Promise<R>;
- $$eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], Arg, R>, arg: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
- $$eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], Arg, R>, arg: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
- $$eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], void, R>, arg?: any, options?: { world?: 'main'|'utility' }): Promise<R>;
- $$eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], void, R>, arg?: any, options?: { world?: 'main'|'utility' }): Promise<R>;
+ $$eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], Arg, R>, arg: Arg): Promise<R>;
+ $$eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], Arg, R>, arg: Arg): Promise<R>;
+ $$eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], void, R>, arg?: any): Promise<R>;
+ $$eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], void, R>, arg?: any): Promise<R>;
waitForSelector<K extends keyof HTMLElementTagNameMap>(selector: K, options?: ElementHandleWaitForSelectorOptionsNotHidden): Promise<ElementHandleForTag<K>>;
waitForSelector(selector: string, options?: ElementHandleWaitForSelectorOptionsNotHidden): Promise<ElementHandle<SVGElement | HTMLElement>>;
@@ -194,9 +194,9 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
}
export interface Locator {
- evaluate<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(pageFunction: PageFunctionOn<E, Arg, R>, arg?: Arg, options?: { timeout?: number, signal?: AbortSignal, exposeFunctions?: boolean, world?: 'main'|'utility' }): Promise<R>;
+ evaluate<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(pageFunction: PageFunctionOn<E, Arg, R>, arg?: Arg, options?: { timeout?: number, signal?: AbortSignal, exposeFunctions?: boolean }): Promise<R>;
evaluateHandle<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(pageFunction: PageFunctionOn<E, Arg, R>, arg?: Arg, options?: { timeout?: number, signal?: AbortSignal, exposeFunctions?: boolean }): Promise<SmartHandle<R>>;
- evaluateAll<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(pageFunction: PageFunctionOn<E[], Arg, R>, arg?: Arg, options?: { world?: 'main'|'utility' }): Promise<R>;
+ evaluateAll<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(pageFunction: PageFunctionOn<E[], Arg, R>, arg?: Arg): Promise<R>;
waitForFunction<Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(pageFunction: PageFunctionOn<E, Arg, any>, arg?: Arg, options?: { timeout?: number, signal?: AbortSignal }): Promise<void>;
elementHandle(options?: { timeout?: number, signal?: AbortSignal }): Promise<ElementHandle<SVGElement | HTMLElement>>;
highlight(options?: { style?: string | { [key: string]: string | number } }): Promise<Disposable>;