Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(api): update ordering for $eval and $$eval #1623

Merged
merged 2 commits into from
Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 49 additions & 49 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -643,8 +643,8 @@ page.removeListener('request', logRequest);
- [event: 'worker'](#event-worker)
- [page.$(selector)](#pageselector)
- [page.$$(selector)](#pageselector-1)
- [page.$$eval(selector, pageFunction[, arg])](#pageevalselector-pagefunction-arg)
- [page.$eval(selector, pageFunction[, arg])](#pageevalselector-pagefunction-arg-1)
- [page.$eval(selector, pageFunction[, arg])](#pageevalselector-pagefunction-arg)
- [page.$$eval(selector, pageFunction[, arg])](#pageevalselector-pagefunction-arg-1)
- [page.accessibility](#pageaccessibility)
- [page.addInitScript(script[, arg])](#pageaddinitscriptscript-arg)
- [page.addScriptTag(options)](#pageaddscripttagoptions)
Expand Down Expand Up @@ -827,40 +827,40 @@ The method runs `document.querySelectorAll` within the page. If no elements matc

Shortcut for [page.mainFrame().$$(selector)](#frameselector-1).

#### page.$$eval(selector, pageFunction[, arg])
#### page.$eval(selector, pageFunction[, arg])
- `selector` <[string]> A selector to query page for
- `pageFunction` <[function]\([Array]<[Element]>\)> Function to be evaluated in browser context
- `pageFunction` <[function]\([Element]\)> Function to be evaluated in browser context
- `arg` <[Serializable]|[JSHandle]> Optional argument to pass to `pageFunction`
- returns: <[Promise]<[Serializable]>> Promise which resolves to the return value of `pageFunction`

This method runs `Array.from(document.querySelectorAll(selector))` within the page and passes it as the first argument to `pageFunction`.
This method runs `document.querySelector` within the page and passes it as the first argument to `pageFunction`. If there's no element matching `selector`, the method throws an error.

If `pageFunction` returns a [Promise], then `page.$$eval` would wait for the promise to resolve and return its value.
If `pageFunction` returns a [Promise], then `page.$eval` would wait for the promise to resolve and return its value.

Examples:
```js
const divsCounts = await page.$$eval('div', (divs, min) => divs.length >= min, 10);
const searchValue = await page.$eval('#search', el => el.value);
const preloadHref = await page.$eval('link[rel=preload]', el => el.href);
const html = await page.$eval('.main-container', (e, suffix) => e.outerHTML + suffix, 'hello');
```

#### page.$eval(selector, pageFunction[, arg])
Shortcut for [page.mainFrame().$eval(selector, pageFunction)](#frameevalselector-pagefunction-arg).

#### page.$$eval(selector, pageFunction[, arg])
- `selector` <[string]> A selector to query page for
- `pageFunction` <[function]\([Element]\)> Function to be evaluated in browser context
- `pageFunction` <[function]\([Array]<[Element]>\)> Function to be evaluated in browser context
- `arg` <[Serializable]|[JSHandle]> Optional argument to pass to `pageFunction`
- returns: <[Promise]<[Serializable]>> Promise which resolves to the return value of `pageFunction`

This method runs `document.querySelector` within the page and passes it as the first argument to `pageFunction`. If there's no element matching `selector`, the method throws an error.
This method runs `Array.from(document.querySelectorAll(selector))` within the page and passes it as the first argument to `pageFunction`.

If `pageFunction` returns a [Promise], then `page.$eval` would wait for the promise to resolve and return its value.
If `pageFunction` returns a [Promise], then `page.$$eval` would wait for the promise to resolve and return its value.

Examples:
```js
const searchValue = await page.$eval('#search', el => el.value);
const preloadHref = await page.$eval('link[rel=preload]', el => el.href);
const html = await page.$eval('.main-container', (e, suffix) => e.outerHTML + suffix, 'hello');
const divsCounts = await page.$$eval('div', (divs, min) => divs.length >= min, 10);
```

Shortcut for [page.mainFrame().$eval(selector, pageFunction)](#frameevalselector-pagefunction-arg).

#### page.accessibility
- returns: <[Accessibility]>

Expand Down Expand Up @@ -1862,8 +1862,8 @@ An example of getting text from an iframe element:
<!-- GEN:toc -->
- [frame.$(selector)](#frameselector)
- [frame.$$(selector)](#frameselector-1)
- [frame.$$eval(selector, pageFunction[, arg])](#frameevalselector-pagefunction-arg)
- [frame.$eval(selector, pageFunction[, arg])](#frameevalselector-pagefunction-arg-1)
- [frame.$eval(selector, pageFunction[, arg])](#frameevalselector-pagefunction-arg)
- [frame.$$eval(selector, pageFunction[, arg])](#frameevalselector-pagefunction-arg-1)
- [frame.addScriptTag(options)](#frameaddscripttagoptions)
- [frame.addStyleTag(options)](#frameaddstyletagoptions)
- [frame.check(selector, [options])](#framecheckselector-options)
Expand Down Expand Up @@ -1907,36 +1907,36 @@ The method queries frame for the selector. If there's no such element within the

The method runs `document.querySelectorAll` within the frame. If no elements match the selector, the return value resolves to `[]`.

#### frame.$$eval(selector, pageFunction[, arg])
#### frame.$eval(selector, pageFunction[, arg])
- `selector` <[string]> A selector to query frame for
- `pageFunction` <[function]\([Array]<[Element]>\)> Function to be evaluated in browser context
- `pageFunction` <[function]\([Element]\)> Function to be evaluated in browser context
- `arg` <[Serializable]|[JSHandle]> Optional argument to pass to `pageFunction`
- returns: <[Promise]<[Serializable]>> Promise which resolves to the return value of `pageFunction`

This method runs `Array.from(document.querySelectorAll(selector))` within the frame and passes it as the first argument to `pageFunction`.
This method runs `document.querySelector` within the frame and passes it as the first argument to `pageFunction`. If there's no element matching `selector`, the method throws an error.

If `pageFunction` returns a [Promise], then `frame.$$eval` would wait for the promise to resolve and return its value.
If `pageFunction` returns a [Promise], then `frame.$eval` would wait for the promise to resolve and return its value.

Examples:
```js
const divsCounts = await frame.$$eval('div', (divs, min) => divs.length >= min, 10);
const searchValue = await frame.$eval('#search', el => el.value);
const preloadHref = await frame.$eval('link[rel=preload]', el => el.href);
const html = await frame.$eval('.main-container', (e, suffix) => e.outerHTML + suffix, 'hello');
```

#### frame.$eval(selector, pageFunction[, arg])
#### frame.$$eval(selector, pageFunction[, arg])
- `selector` <[string]> A selector to query frame for
- `pageFunction` <[function]\([Element]\)> Function to be evaluated in browser context
- `pageFunction` <[function]\([Array]<[Element]>\)> Function to be evaluated in browser context
- `arg` <[Serializable]|[JSHandle]> Optional argument to pass to `pageFunction`
- returns: <[Promise]<[Serializable]>> Promise which resolves to the return value of `pageFunction`

This method runs `document.querySelector` within the frame and passes it as the first argument to `pageFunction`. If there's no element matching `selector`, the method throws an error.
This method runs `Array.from(document.querySelectorAll(selector))` within the frame and passes it as the first argument to `pageFunction`.

If `pageFunction` returns a [Promise], then `frame.$eval` would wait for the promise to resolve and return its value.
If `pageFunction` returns a [Promise], then `frame.$$eval` would wait for the promise to resolve and return its value.

Examples:
```js
const searchValue = await frame.$eval('#search', el => el.value);
const preloadHref = await frame.$eval('link[rel=preload]', el => el.href);
const html = await frame.$eval('.main-container', (e, suffix) => e.outerHTML + suffix, 'hello');
const divsCounts = await frame.$$eval('div', (divs, min) => divs.length >= min, 10);
```

#### frame.addScriptTag(options)
Expand Down Expand Up @@ -2472,8 +2472,8 @@ ElementHandle instances can be used as an argument in [`page.$eval()`](#pageeval
<!-- GEN:toc -->
- [elementHandle.$(selector)](#elementhandleselector)
- [elementHandle.$$(selector)](#elementhandleselector-1)
- [elementHandle.$$eval(selector, pageFunction[, arg])](#elementhandleevalselector-pagefunction-arg)
- [elementHandle.$eval(selector, pageFunction[, arg])](#elementhandleevalselector-pagefunction-arg-1)
- [elementHandle.$eval(selector, pageFunction[, arg])](#elementhandleevalselector-pagefunction-arg)
- [elementHandle.$$eval(selector, pageFunction[, arg])](#elementhandleevalselector-pagefunction-arg-1)
- [elementHandle.boundingBox()](#elementhandleboundingbox)
- [elementHandle.check([options])](#elementhandlecheckoptions)
- [elementHandle.click([options])](#elementhandleclickoptions)
Expand Down Expand Up @@ -2514,6 +2514,23 @@ The method runs `element.querySelector` within the page. If no element matches t

The method runs `element.querySelectorAll` within the page. If no elements match the selector, the return value resolves to `[]`.

#### elementHandle.$eval(selector, pageFunction[, arg])
- `selector` <[string]> A selector to query page for
- `pageFunction` <[function]\([Element]\)> Function to be evaluated in browser context
- `arg` <[Serializable]|[JSHandle]> Optional argument to pass to `pageFunction`
- returns: <[Promise]<[Serializable]>> Promise which resolves to the return value of `pageFunction`

This method runs `document.querySelector` within the element and passes it as the first argument to `pageFunction`. If there's no element matching `selector`, the method throws an error.

If `pageFunction` returns a [Promise], then `frame.$eval` would wait for the promise to resolve and return its value.

Examples:
```js
const tweetHandle = await page.$('.tweet');
expect(await tweetHandle.$eval('.like', node => node.innerText)).toBe('100');
expect(await tweetHandle.$eval('.retweets', node => node.innerText)).toBe('10');
```

#### elementHandle.$$eval(selector, pageFunction[, arg])
- `selector` <[string]> A selector to query page for
- `pageFunction` <[function]\([Array]<[Element]>\)> Function to be evaluated in browser context
Expand All @@ -2536,23 +2553,6 @@ const feedHandle = await page.$('.feed');
expect(await feedHandle.$$eval('.tweet', nodes => nodes.map(n => n.innerText))).toEqual(['Hello!', 'Hi!']);
```

#### elementHandle.$eval(selector, pageFunction[, arg])
- `selector` <[string]> A selector to query page for
- `pageFunction` <[function]\([Element]\)> Function to be evaluated in browser context
- `arg` <[Serializable]|[JSHandle]> Optional argument to pass to `pageFunction`
- returns: <[Promise]<[Serializable]>> Promise which resolves to the return value of `pageFunction`

This method runs `document.querySelector` within the element and passes it as the first argument to `pageFunction`. If there's no element matching `selector`, the method throws an error.

If `pageFunction` returns a [Promise], then `frame.$eval` would wait for the promise to resolve and return its value.

Examples:
```js
const tweetHandle = await page.$('.tweet');
expect(await tweetHandle.$eval('.like', node => node.innerText)).toBe('100');
expect(await tweetHandle.$eval('.retweets', node => node.innerText)).toBe('10');
```

#### elementHandle.boundingBox()
- returns: <[Promise]<?[Object]>>
- x <[number]> the x coordinate of the element in pixels.
Expand Down
2 changes: 1 addition & 1 deletion utils/doclint/check_public_api/Documentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Documentation.Class = class {
continue;
if (member1.kind === 'method' && member1.name === 'constructor')
continue;
if (member1.name > member2.name) {
if (member1.name.replace(/^\$+/, '$') > member2.name.replace(/^\$+/, '$')) {
let memberName1 = `${this.name}.${member1.name}`;
if (member1.kind === 'method')
memberName1 += '()';
Expand Down