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

chore(docs): document Frame class #6188

Merged
merged 2 commits into from Jul 9, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion new-docs/puppeteer.frame._.md
Expand Up @@ -4,6 +4,8 @@

## Frame.$() method

This method queries the frame for the given selector.

<b>Signature:</b>

```typescript
Expand All @@ -14,9 +16,11 @@ $(selector: string): Promise<ElementHandle | null>;

| Parameter | Type | Description |
| --- | --- | --- |
| selector | string | |
| selector | string | a selector to query for. |

<b>Returns:</b>

Promise&lt;[ElementHandle](./puppeteer.elementhandle.md) \| null&gt;

A promise which resolves to an `ElementHandle` pointing at the element, or `null` if it was not found.

6 changes: 5 additions & 1 deletion new-docs/puppeteer.frame.__.md
Expand Up @@ -4,6 +4,8 @@

## Frame.$$() method

This runs `document.querySelectorAll` in the frame and returns the result.

<b>Signature:</b>

```typescript
Expand All @@ -14,9 +16,11 @@ $$(selector: string): Promise<ElementHandle[]>;

| Parameter | Type | Description |
| --- | --- | --- |
| selector | string | |
| selector | string | a selector to search for |

<b>Returns:</b>

Promise&lt;[ElementHandle](./puppeteer.elementhandle.md)<!-- -->\[\]&gt;

An array of element handles pointing to the found frame elements.

20 changes: 17 additions & 3 deletions new-docs/puppeteer.frame.__eval.md
Expand Up @@ -14,11 +14,25 @@ $$eval<ReturnType>(selector: string, pageFunction: (elements: Element[], ...args

| Parameter | Type | Description |
| --- | --- | --- |
| selector | string | |
| pageFunction | (elements: Element\[\], ...args: unknown\[\]) =&gt; ReturnType \| Promise&lt;ReturnType&gt; | |
| args | [SerializableOrJSHandle](./puppeteer.serializableorjshandle.md)<!-- -->\[\] | |
| selector | string | the selector to query for |
| pageFunction | (elements: Element\[\], ...args: unknown\[\]) =&gt; ReturnType \| Promise&lt;ReturnType&gt; | the function to be evaluated in the frame's context |
| args | [SerializableOrJSHandle](./puppeteer.serializableorjshandle.md)<!-- -->\[\] | additional arguments to pass to <code>pageFuncton</code> |

<b>Returns:</b>

Promise&lt;[WrapElementHandle](./puppeteer.wrapelementhandle.md)<!-- -->&lt;ReturnType&gt;&gt;

## Remarks

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.

## Example


```js
const divsCounts = await frame.$$eval('div', divs => divs.length);

```

15 changes: 0 additions & 15 deletions new-docs/puppeteer.frame._detach.md

This file was deleted.

20 changes: 17 additions & 3 deletions new-docs/puppeteer.frame._eval.md
Expand Up @@ -14,11 +14,25 @@ $eval<ReturnType>(selector: string, pageFunction: (element: Element, ...args: un

| Parameter | Type | Description |
| --- | --- | --- |
| selector | string | |
| pageFunction | (element: Element, ...args: unknown\[\]) =&gt; ReturnType \| Promise&lt;ReturnType&gt; | |
| args | [SerializableOrJSHandle](./puppeteer.serializableorjshandle.md)<!-- -->\[\] | |
| selector | string | the selector to query for |
| pageFunction | (element: Element, ...args: unknown\[\]) =&gt; ReturnType \| Promise&lt;ReturnType&gt; | the function to be evaluated in the frame's context |
| args | [SerializableOrJSHandle](./puppeteer.serializableorjshandle.md)<!-- -->\[\] | additional arguments to pass to <code>pageFuncton</code> |

<b>Returns:</b>

Promise&lt;[WrapElementHandle](./puppeteer.wrapelementhandle.md)<!-- -->&lt;ReturnType&gt;&gt;

## Remarks

This method runs `document.querySelector` 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.

## Example


```js
const searchValue = await frame.$eval('#search', el => el.value);

```

22 changes: 0 additions & 22 deletions new-docs/puppeteer.frame._navigated.md

This file was deleted.

22 changes: 0 additions & 22 deletions new-docs/puppeteer.frame._navigatedwithindocument.md

This file was deleted.

23 changes: 0 additions & 23 deletions new-docs/puppeteer.frame._onlifecycleevent.md

This file was deleted.

15 changes: 0 additions & 15 deletions new-docs/puppeteer.frame._onloadingstopped.md

This file was deleted.

4 changes: 3 additions & 1 deletion new-docs/puppeteer.frame._x.md
Expand Up @@ -4,6 +4,8 @@

## Frame.$x() method

This method evaluates the given XPath expression and returns the results.

<b>Signature:</b>

```typescript
Expand All @@ -14,7 +16,7 @@ $x(expression: string): Promise<ElementHandle[]>;

| Parameter | Type | Description |
| --- | --- | --- |
| expression | string | |
| expression | string | the XPath expression to evaluate. |

<b>Returns:</b>

Expand Down
13 changes: 6 additions & 7 deletions new-docs/puppeteer.frame.addscripttag.md
Expand Up @@ -4,24 +4,23 @@

## Frame.addScriptTag() method

Adds a `<script>` tag into the page with the desired url or content.

<b>Signature:</b>

```typescript
addScriptTag(options: {
url?: string;
path?: string;
content?: string;
type?: string;
}): Promise<ElementHandle>;
addScriptTag(options: FrameAddScriptTagOptions): Promise<ElementHandle>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| options | { url?: string; path?: string; content?: string; type?: string; } | |
| options | [FrameAddScriptTagOptions](./puppeteer.frameaddscripttagoptions.md) | configure the script to add to the page. |

<b>Returns:</b>

Promise&lt;[ElementHandle](./puppeteer.elementhandle.md)<!-- -->&gt;

a promise that resolves to the added tag when the script's `onload` event fires or when the script content was injected into the frame.

12 changes: 6 additions & 6 deletions new-docs/puppeteer.frame.addstyletag.md
Expand Up @@ -4,23 +4,23 @@

## Frame.addStyleTag() method

Adds a `<link rel="stylesheet">` tag into the page with the desired url or a `<style type="text/css">` tag with the content.

<b>Signature:</b>

```typescript
addStyleTag(options: {
url?: string;
path?: string;
content?: string;
}): Promise<ElementHandle>;
addStyleTag(options: FrameAddStyleTagOptions): Promise<ElementHandle>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| options | { url?: string; path?: string; content?: string; } | |
| options | [FrameAddStyleTagOptions](./puppeteer.frameaddstyletagoptions.md) | configure the CSS to add to the page. |

<b>Returns:</b>

Promise&lt;[ElementHandle](./puppeteer.elementhandle.md)<!-- -->&gt;

a promise that resolves to the added tag when the stylesheets's `onload` event fires or when the CSS content was injected into the frame.

2 changes: 2 additions & 0 deletions new-docs/puppeteer.frame.childframes.md
Expand Up @@ -13,3 +13,5 @@ childFrames(): Frame[];

[Frame](./puppeteer.frame.md)<!-- -->\[\]

an array of child frames.

18 changes: 17 additions & 1 deletion new-docs/puppeteer.frame.click.md
Expand Up @@ -4,6 +4,8 @@

## Frame.click() method

This method clicks the first element found that matches `selector`<!-- -->.

<b>Signature:</b>

```typescript
Expand All @@ -18,10 +20,24 @@ click(selector: string, options?: {

| Parameter | Type | Description |
| --- | --- | --- |
| selector | string | |
| selector | string | the selector to search for to click. If there are multiple elements, the first will be clicked. |
| options | { delay?: number; button?: [MouseButton](./puppeteer.mousebutton.md)<!-- -->; clickCount?: number; } | |

<b>Returns:</b>

Promise&lt;void&gt;

## Remarks

This method scrolls the element into view if needed, and then uses [Page.mouse](./puppeteer.page.mouse.md) to click in the center of the element. If there's no element matching `selector`<!-- -->, the method throws an error.

Bear in mind that if `click()` triggers a navigation event and there's a separate `page.waitForNavigation()` promise to be resolved, you may end up with a race condition that yields unexpected results. The correct pattern for click and wait for navigation is the following:

```javascript
const [response] = await Promise.all([
page.waitForNavigation(waitOptions),
frame.click(selector, clickOptions),
]);

```

2 changes: 2 additions & 0 deletions new-docs/puppeteer.frame.content.md
Expand Up @@ -13,3 +13,5 @@ content(): Promise<string>;

Promise&lt;string&gt;

the full HTML contents of the frame, including the doctype.

8 changes: 6 additions & 2 deletions new-docs/puppeteer.frame.evaluate.md
Expand Up @@ -14,10 +14,14 @@ evaluate<ReturnType extends any>(pageFunction: Function | string, ...args: unkno

| Parameter | Type | Description |
| --- | --- | --- |
| pageFunction | Function \| string | |
| args | unknown\[\] | |
| pageFunction | Function \| string | a function that is run within the frame |
| args | unknown\[\] | arguments to be passed to the pageFunction |

<b>Returns:</b>

Promise&lt;ReturnType&gt;

## Remarks

This method behaves identically to [Page.evaluate()](./puppeteer.page.evaluate.md) except it's run within the context of the `frame`<!-- -->, rather than the entire page.

10 changes: 8 additions & 2 deletions new-docs/puppeteer.frame.evaluatehandle.md
Expand Up @@ -14,10 +14,16 @@ evaluateHandle<HandlerType extends JSHandle = JSHandle>(pageFunction: EvaluateHa

| Parameter | Type | Description |
| --- | --- | --- |
| pageFunction | [EvaluateHandleFn](./puppeteer.evaluatehandlefn.md) | |
| args | [SerializableOrJSHandle](./puppeteer.serializableorjshandle.md)<!-- -->\[\] | |
| pageFunction | [EvaluateHandleFn](./puppeteer.evaluatehandlefn.md) | a function that is run within the frame |
| args | [SerializableOrJSHandle](./puppeteer.serializableorjshandle.md)<!-- -->\[\] | arguments to be passed to the pageFunction |

<b>Returns:</b>

Promise&lt;HandlerType&gt;

## Remarks

The only difference between [Frame.evaluate()](./puppeteer.frame.evaluate.md) and `frame.evaluateHandle` is that `evaluateHandle` will return the value wrapped in an in-page object.

This method behaves identically to [Page.evaluateHandle()](./puppeteer.page.evaluatehandle.md) except it's run within the context of the `frame`<!-- -->, rather than the entire page.

2 changes: 2 additions & 0 deletions new-docs/puppeteer.frame.executioncontext.md
Expand Up @@ -13,3 +13,5 @@ executionContext(): Promise<ExecutionContext>;

Promise&lt;[ExecutionContext](./puppeteer.executioncontext.md)<!-- -->&gt;

a promise that resolves to the frame's default execution context.

8 changes: 7 additions & 1 deletion new-docs/puppeteer.frame.focus.md
Expand Up @@ -4,6 +4,8 @@

## Frame.focus() method

This method fetches an element with `selector` and focuses it.

<b>Signature:</b>

```typescript
Expand All @@ -14,9 +16,13 @@ focus(selector: string): Promise<void>;

| Parameter | Type | Description |
| --- | --- | --- |
| selector | string | |
| selector | string | the selector for the element to focus. If there are multiple elements, the first will be focused. |

<b>Returns:</b>

Promise&lt;void&gt;

## Remarks

If there's no element matching `selector`<!-- -->, the method throws an error.