refactor: migrate browsingContext methods to frame (#10881)
This commit is contained in:
parent
a0e57f7eb2
commit
60582b7fbc
@ -94,6 +94,7 @@ sidebar_label: API
|
|||||||
| [FrameEvents](./puppeteer.frameevents.md) | |
|
| [FrameEvents](./puppeteer.frameevents.md) | |
|
||||||
| [FrameWaitForFunctionOptions](./puppeteer.framewaitforfunctionoptions.md) | |
|
| [FrameWaitForFunctionOptions](./puppeteer.framewaitforfunctionoptions.md) | |
|
||||||
| [GeolocationOptions](./puppeteer.geolocationoptions.md) | |
|
| [GeolocationOptions](./puppeteer.geolocationoptions.md) | |
|
||||||
|
| [GoToOptions](./puppeteer.gotooptions.md) | |
|
||||||
| [InterceptResolutionState](./puppeteer.interceptresolutionstate.md) | |
|
| [InterceptResolutionState](./puppeteer.interceptresolutionstate.md) | |
|
||||||
| [InternalNetworkConditions](./puppeteer.internalnetworkconditions.md) | |
|
| [InternalNetworkConditions](./puppeteer.internalnetworkconditions.md) | |
|
||||||
| [JSCoverageEntry](./puppeteer.jscoverageentry.md) | The CoverageEntry class for JavaScript |
|
| [JSCoverageEntry](./puppeteer.jscoverageentry.md) | The CoverageEntry class for JavaScript |
|
||||||
|
@ -4,7 +4,7 @@ sidebar_label: Frame.goto
|
|||||||
|
|
||||||
# Frame.goto() method
|
# Frame.goto() method
|
||||||
|
|
||||||
Navigates a frame to the given url.
|
Navigates the frame to the given `url`.
|
||||||
|
|
||||||
#### Signature:
|
#### Signature:
|
||||||
|
|
||||||
@ -24,10 +24,10 @@ class Frame {
|
|||||||
|
|
||||||
## Parameters
|
## Parameters
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
| Parameter | Type | Description |
|
||||||
| --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------- |
|
||||||
| url | string | the URL to navigate the frame to. This should include the scheme, e.g. <code>https://</code>. |
|
| url | string | URL to navigate the frame to. The URL should include scheme, e.g. <code>https://</code> |
|
||||||
| options | { referer?: string; referrerPolicy?: string; timeout?: number; waitUntil?: [PuppeteerLifeCycleEvent](./puppeteer.puppeteerlifecycleevent.md) \| [PuppeteerLifeCycleEvent](./puppeteer.puppeteerlifecycleevent.md)\[\]; } | _(Optional)_ navigation options. <code>waitUntil</code> is useful to define when the navigation should be considered successful - see the docs for [PuppeteerLifeCycleEvent](./puppeteer.puppeteerlifecycleevent.md) for more details. |
|
| options | { referer?: string; referrerPolicy?: string; timeout?: number; waitUntil?: [PuppeteerLifeCycleEvent](./puppeteer.puppeteerlifecycleevent.md) \| [PuppeteerLifeCycleEvent](./puppeteer.puppeteerlifecycleevent.md)\[\]; } | _(Optional)_ Options to configure waiting behavior. |
|
||||||
|
|
||||||
**Returns:**
|
**Returns:**
|
||||||
|
|
||||||
@ -37,9 +37,9 @@ A promise which resolves to the main resource response. In case of multiple redi
|
|||||||
|
|
||||||
## Exceptions
|
## Exceptions
|
||||||
|
|
||||||
This method will throw an error if:
|
If:
|
||||||
|
|
||||||
- there's an SSL error (e.g. in case of self-signed certificates). - target URL is invalid. - the `timeout` is exceeded during navigation. - the remote server does not respond or is unreachable. - the main resource failed to load.
|
- there's an SSL error (e.g. in case of self-signed certificates). - target URL is invalid. - the timeout is exceeded during navigation. - the remote server does not respond or is unreachable. - the main resource failed to load.
|
||||||
|
|
||||||
This method will not throw an error when any valid HTTP status code is returned by the remote server, including 404 "Not Found" and 500 "Internal Server Error". The status code for such responses can be retrieved by calling [HTTPResponse.status()](./puppeteer.httpresponse.status.md).
|
This method will not throw an error when any valid HTTP status code is returned by the remote server, including 404 "Not Found" and 500 "Internal Server Error". The status code for such responses can be retrieved by calling [HTTPResponse.status()](./puppeteer.httpresponse.status.md).
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ console.log(text);
|
|||||||
| [evaluate(pageFunction, args)](./puppeteer.frame.evaluate.md) | | Behaves identically to [Page.evaluate()](./puppeteer.page.evaluate.md) except it's run within the the context of this frame. |
|
| [evaluate(pageFunction, args)](./puppeteer.frame.evaluate.md) | | Behaves identically to [Page.evaluate()](./puppeteer.page.evaluate.md) except it's run within the the context of this frame. |
|
||||||
| [evaluateHandle(pageFunction, args)](./puppeteer.frame.evaluatehandle.md) | | Behaves identically to [Page.evaluateHandle()](./puppeteer.page.evaluatehandle.md) except it's run within the context of this frame. |
|
| [evaluateHandle(pageFunction, args)](./puppeteer.frame.evaluatehandle.md) | | Behaves identically to [Page.evaluateHandle()](./puppeteer.page.evaluatehandle.md) except it's run within the context of this frame. |
|
||||||
| [focus(selector)](./puppeteer.frame.focus.md) | | Focuses the first element that matches the <code>selector</code>. |
|
| [focus(selector)](./puppeteer.frame.focus.md) | | Focuses the first element that matches the <code>selector</code>. |
|
||||||
| [goto(url, options)](./puppeteer.frame.goto.md) | | Navigates a frame to the given url. |
|
| [goto(url, options)](./puppeteer.frame.goto.md) | | Navigates the frame to the given <code>url</code>. |
|
||||||
| [hover(selector)](./puppeteer.frame.hover.md) | | Hovers the pointer over the center of the first element that matches the <code>selector</code>. |
|
| [hover(selector)](./puppeteer.frame.hover.md) | | Hovers the pointer over the center of the first element that matches the <code>selector</code>. |
|
||||||
| [isDetached()](./puppeteer.frame.isdetached.md) | | Is<code>true</code> if the frame has been detached. Otherwise, <code>false</code>. |
|
| [isDetached()](./puppeteer.frame.isdetached.md) | | Is<code>true</code> if the frame has been detached. Otherwise, <code>false</code>. |
|
||||||
| [isOOPFrame()](./puppeteer.frame.isoopframe.md) | | Is <code>true</code> if the frame is an out-of-process (OOP) frame. Otherwise, <code>false</code>. |
|
| [isOOPFrame()](./puppeteer.frame.isoopframe.md) | | Is <code>true</code> if the frame is an out-of-process (OOP) frame. Otherwise, <code>false</code>. |
|
||||||
|
@ -12,24 +12,23 @@ Usage of the [History API](https://developer.mozilla.org/en-US/docs/Web/API/Hist
|
|||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
class Frame {
|
class Frame {
|
||||||
abstract waitForNavigation(options?: {
|
abstract waitForNavigation(
|
||||||
timeout?: number;
|
options?: WaitForOptions
|
||||||
waitUntil?: PuppeteerLifeCycleEvent | PuppeteerLifeCycleEvent[];
|
): Promise<HTTPResponse | null>;
|
||||||
}): Promise<HTTPResponse | null>;
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Parameters
|
## Parameters
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
| Parameter | Type | Description |
|
||||||
| --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------- |
|
| --------- | ----------------------------------------------- | --------------------------------------------------- |
|
||||||
| options | { timeout?: number; waitUntil?: [PuppeteerLifeCycleEvent](./puppeteer.puppeteerlifecycleevent.md) \| [PuppeteerLifeCycleEvent](./puppeteer.puppeteerlifecycleevent.md)\[\]; } | _(Optional)_ options to configure when the navigation is consided finished. |
|
| options | [WaitForOptions](./puppeteer.waitforoptions.md) | _(Optional)_ Options to configure waiting behavior. |
|
||||||
|
|
||||||
**Returns:**
|
**Returns:**
|
||||||
|
|
||||||
Promise<[HTTPResponse](./puppeteer.httpresponse.md) \| null>
|
Promise<[HTTPResponse](./puppeteer.httpresponse.md) \| null>
|
||||||
|
|
||||||
a promise that resolves when the frame navigates to a new URL.
|
A promise which resolves to the main resource response.
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
|
20
docs/api/puppeteer.gotooptions.md
Normal file
20
docs/api/puppeteer.gotooptions.md
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
---
|
||||||
|
sidebar_label: GoToOptions
|
||||||
|
---
|
||||||
|
|
||||||
|
# GoToOptions interface
|
||||||
|
|
||||||
|
#### Signature:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
export interface GoToOptions extends WaitForOptions
|
||||||
|
```
|
||||||
|
|
||||||
|
**Extends:** [WaitForOptions](./puppeteer.waitforoptions.md)
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
|
||||||
|
| Property | Modifiers | Type | Description | Default |
|
||||||
|
| -------------- | --------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
|
||||||
|
| referer | <code>optional</code> | string | If provided, it will take preference over the referer header value set by [page.setExtraHTTPHeaders()](./puppeteer.page.setextrahttpheaders.md). | |
|
||||||
|
| referrerPolicy | <code>optional</code> | string | If provided, it will take preference over the referer-policy header value set by [page.setExtraHTTPHeaders()](./puppeteer.page.setextrahttpheaders.md). | |
|
@ -4,51 +4,45 @@ sidebar_label: Page.goto
|
|||||||
|
|
||||||
# Page.goto() method
|
# Page.goto() method
|
||||||
|
|
||||||
|
Navigates the page to the given `url`.
|
||||||
|
|
||||||
#### Signature:
|
#### Signature:
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
class Page {
|
class Page {
|
||||||
goto(
|
goto(url: string, options?: GoToOptions): Promise<HTTPResponse | null>;
|
||||||
url: string,
|
|
||||||
options?: WaitForOptions & {
|
|
||||||
referer?: string;
|
|
||||||
referrerPolicy?: string;
|
|
||||||
}
|
|
||||||
): Promise<HTTPResponse | null>;
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Parameters
|
## Parameters
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
| Parameter | Type | Description |
|
||||||
| --------- | ---------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
|
| --------- | ----------------------------------------- | ---------------------------------------------------------------------------------- |
|
||||||
| url | string | URL to navigate page to. The URL should include scheme, e.g. <code>https://</code> |
|
| url | string | URL to navigate page to. The URL should include scheme, e.g. <code>https://</code> |
|
||||||
| options | [WaitForOptions](./puppeteer.waitforoptions.md) & { referer?: string; referrerPolicy?: string; } | _(Optional)_ Navigation Parameter |
|
| options | [GoToOptions](./puppeteer.gotooptions.md) | _(Optional)_ Options to configure waiting behavior. |
|
||||||
|
|
||||||
**Returns:**
|
**Returns:**
|
||||||
|
|
||||||
Promise<[HTTPResponse](./puppeteer.httpresponse.md) \| null>
|
Promise<[HTTPResponse](./puppeteer.httpresponse.md) \| null>
|
||||||
|
|
||||||
Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect.
|
A promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect.
|
||||||
|
|
||||||
## Remarks
|
## Exceptions
|
||||||
|
|
||||||
The argument `options` might have the following properties:
|
If:
|
||||||
|
|
||||||
- `timeout` : Maximum navigation time in milliseconds, defaults to 30 seconds, pass 0 to disable timeout. The default value can be changed by using the [Page.setDefaultNavigationTimeout()](./puppeteer.page.setdefaultnavigationtimeout.md) or [Page.setDefaultTimeout()](./puppeteer.page.setdefaulttimeout.md) methods.
|
|
||||||
|
|
||||||
- `waitUntil`:When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either:<br/> - `load` : consider navigation to be finished when the load event is fired.<br/> - `domcontentloaded` : consider navigation to be finished when the DOMContentLoaded event is fired.<br/> - `networkidle0` : consider navigation to be finished when there are no more than 0 network connections for at least `500` ms.<br/> - `networkidle2` : consider navigation to be finished when there are no more than 2 network connections for at least `500` ms.
|
|
||||||
|
|
||||||
- `referer` : Referer header value. If provided it will take preference over the referer header value set by [page.setExtraHTTPHeaders()](./puppeteer.page.setextrahttpheaders.md).<br/> - `referrerPolicy` : ReferrerPolicy. If provided it will take preference over the referer-policy header value set by [page.setExtraHTTPHeaders()](./puppeteer.page.setextrahttpheaders.md).
|
|
||||||
|
|
||||||
`page.goto` will throw an error if:
|
|
||||||
|
|
||||||
- there's an SSL error (e.g. in case of self-signed certificates). - target URL is invalid. - the timeout is exceeded during navigation. - the remote server does not respond or is unreachable. - the main resource failed to load.
|
- there's an SSL error (e.g. in case of self-signed certificates). - target URL is invalid. - the timeout is exceeded during navigation. - the remote server does not respond or is unreachable. - the main resource failed to load.
|
||||||
|
|
||||||
`page.goto` will not throw an error when any valid HTTP status code is returned by the remote server, including 404 "Not Found" and 500 "Internal Server Error". The status code for such responses can be retrieved by calling response.status().
|
This method will not throw an error when any valid HTTP status code is returned by the remote server, including 404 "Not Found" and 500 "Internal Server Error". The status code for such responses can be retrieved by calling [HTTPResponse.status()](./puppeteer.httpresponse.status.md).
|
||||||
|
|
||||||
NOTE: `page.goto` either throws an error or returns a main resource response. The only exceptions are navigation to about:blank or navigation to the same URL with a different hash, which would succeed and return null.
|
## Remarks
|
||||||
|
|
||||||
NOTE: Headless mode doesn't support navigation to a PDF document. See the [upstream issue](https://bugs.chromium.org/p/chromium/issues/detail?id=761295).
|
Navigation to `about:blank` or navigation to the same URL with a different hash will succeed and return `null`.
|
||||||
|
|
||||||
|
:::warning
|
||||||
|
|
||||||
|
Headless mode doesn't support navigation to a PDF document. See the [upstream issue](https://bugs.chromium.org/p/chromium/issues/detail?id=761295).
|
||||||
|
|
||||||
|
:::
|
||||||
|
|
||||||
Shortcut for [page.mainFrame().goto(url, options)](./puppeteer.frame.goto.md).
|
Shortcut for [page.mainFrame().goto(url, options)](./puppeteer.frame.goto.md).
|
||||||
|
@ -112,7 +112,7 @@ page.off('request', logRequest);
|
|||||||
| [getDefaultTimeout()](./puppeteer.page.getdefaulttimeout.md) | | Maximum time in milliseconds. |
|
| [getDefaultTimeout()](./puppeteer.page.getdefaulttimeout.md) | | Maximum time in milliseconds. |
|
||||||
| [goBack(options)](./puppeteer.page.goback.md) | | This method navigate to the previous page in history. |
|
| [goBack(options)](./puppeteer.page.goback.md) | | This method navigate to the previous page in history. |
|
||||||
| [goForward(options)](./puppeteer.page.goforward.md) | | This method navigate to the next page in history. |
|
| [goForward(options)](./puppeteer.page.goforward.md) | | This method navigate to the next page in history. |
|
||||||
| [goto(url, options)](./puppeteer.page.goto.md) | | |
|
| [goto(url, options)](./puppeteer.page.goto.md) | | Navigates the page to the given <code>url</code>. |
|
||||||
| [hover(selector)](./puppeteer.page.hover.md) | | This method fetches an element with <code>selector</code>, scrolls it into view if needed, and then uses [Page.mouse](./puppeteer.page.md) to hover over the center of the element. If there's no element matching <code>selector</code>, the method throws an error. |
|
| [hover(selector)](./puppeteer.page.hover.md) | | This method fetches an element with <code>selector</code>, scrolls it into view if needed, and then uses [Page.mouse](./puppeteer.page.md) to hover over the center of the element. If there's no element matching <code>selector</code>, the method throws an error. |
|
||||||
| [isClosed()](./puppeteer.page.isclosed.md) | | Indicates that the page has been closed. |
|
| [isClosed()](./puppeteer.page.isclosed.md) | | Indicates that the page has been closed. |
|
||||||
| [isDragInterceptionEnabled()](./puppeteer.page.isdraginterceptionenabled.md) | | <code>true</code> if drag events are being intercepted, <code>false</code> otherwise. |
|
| [isDragInterceptionEnabled()](./puppeteer.page.isdraginterceptionenabled.md) | | <code>true</code> if drag events are being intercepted, <code>false</code> otherwise. |
|
||||||
@ -124,7 +124,7 @@ page.off('request', logRequest);
|
|||||||
| [metrics()](./puppeteer.page.metrics.md) | | Object containing metrics as key/value pairs. |
|
| [metrics()](./puppeteer.page.metrics.md) | | Object containing metrics as key/value pairs. |
|
||||||
| [pdf(options)](./puppeteer.page.pdf.md) | | Generates a PDF of the page with the <code>print</code> CSS media type. |
|
| [pdf(options)](./puppeteer.page.pdf.md) | | Generates a PDF of the page with the <code>print</code> CSS media type. |
|
||||||
| [queryObjects(prototypeHandle)](./puppeteer.page.queryobjects.md) | | This method iterates the JavaScript heap and finds all objects with the given prototype. |
|
| [queryObjects(prototypeHandle)](./puppeteer.page.queryobjects.md) | | This method iterates the JavaScript heap and finds all objects with the given prototype. |
|
||||||
| [reload(options)](./puppeteer.page.reload.md) | | |
|
| [reload(options)](./puppeteer.page.reload.md) | | Reloads the page. |
|
||||||
| [removeExposedFunction(name)](./puppeteer.page.removeexposedfunction.md) | | The method removes a previously added function via $[Page.exposeFunction()](./puppeteer.page.exposefunction.md) called <code>name</code> from the page's <code>window</code> object. |
|
| [removeExposedFunction(name)](./puppeteer.page.removeexposedfunction.md) | | The method removes a previously added function via $[Page.exposeFunction()](./puppeteer.page.exposefunction.md) called <code>name</code> from the page's <code>window</code> object. |
|
||||||
| [removeScriptToEvaluateOnNewDocument(identifier)](./puppeteer.page.removescripttoevaluateonnewdocument.md) | | Removes script that injected into page by Page.evaluateOnNewDocument. |
|
| [removeScriptToEvaluateOnNewDocument(identifier)](./puppeteer.page.removescripttoevaluateonnewdocument.md) | | Removes script that injected into page by Page.evaluateOnNewDocument. |
|
||||||
| [screenshot(options)](./puppeteer.page.screenshot.md) | | Captures screenshot of the current page. |
|
| [screenshot(options)](./puppeteer.page.screenshot.md) | | Captures screenshot of the current page. |
|
||||||
|
@ -4,6 +4,8 @@ sidebar_label: Page.reload
|
|||||||
|
|
||||||
# Page.reload() method
|
# Page.reload() method
|
||||||
|
|
||||||
|
Reloads the page.
|
||||||
|
|
||||||
#### Signature:
|
#### Signature:
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
@ -14,20 +16,12 @@ class Page {
|
|||||||
|
|
||||||
## Parameters
|
## Parameters
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
| Parameter | Type | Description |
|
||||||
| --------- | ----------------------------------------------- | ----------------------------------------------------------------------------- |
|
| --------- | ----------------------------------------------- | --------------------------------------------------- |
|
||||||
| options | [WaitForOptions](./puppeteer.waitforoptions.md) | _(Optional)_ Navigation parameters which might have the following properties: |
|
| options | [WaitForOptions](./puppeteer.waitforoptions.md) | _(Optional)_ Options to configure waiting behavior. |
|
||||||
|
|
||||||
**Returns:**
|
**Returns:**
|
||||||
|
|
||||||
Promise<[HTTPResponse](./puppeteer.httpresponse.md) \| null>
|
Promise<[HTTPResponse](./puppeteer.httpresponse.md) \| null>
|
||||||
|
|
||||||
Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect.
|
A promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect.
|
||||||
|
|
||||||
## Remarks
|
|
||||||
|
|
||||||
The argument `options` might have the following properties:
|
|
||||||
|
|
||||||
- `timeout` : Maximum navigation time in milliseconds, defaults to 30 seconds, pass 0 to disable timeout. The default value can be changed by using the [Page.setDefaultNavigationTimeout()](./puppeteer.page.setdefaultnavigationtimeout.md) or [Page.setDefaultTimeout()](./puppeteer.page.setdefaulttimeout.md) methods.
|
|
||||||
|
|
||||||
- `waitUntil`: When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either:<br/> - `load` : consider navigation to be finished when the load event is fired.<br/> - `domcontentloaded` : consider navigation to be finished when the DOMContentLoaded event is fired.<br/> - `networkidle0` : consider navigation to be finished when there are no more than 0 network connections for at least `500` ms.<br/> - `networkidle2` : consider navigation to be finished when there are no more than 2 network connections for at least `500` ms.
|
|
||||||
|
@ -8,8 +8,22 @@ sidebar_label: PuppeteerLifeCycleEvent
|
|||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
export type PuppeteerLifeCycleEvent =
|
export type PuppeteerLifeCycleEvent =
|
||||||
|
/**
|
||||||
|
* Waits for the 'load' event.
|
||||||
|
*/
|
||||||
| 'load'
|
| 'load'
|
||||||
|
/**
|
||||||
|
* Waits for the 'DOMContentLoaded' event.
|
||||||
|
*/
|
||||||
| 'domcontentloaded'
|
| 'domcontentloaded'
|
||||||
|
/**
|
||||||
|
* Waits till there are no more than 0 network connections for at least `500`
|
||||||
|
* ms.
|
||||||
|
*/
|
||||||
| 'networkidle0'
|
| 'networkidle0'
|
||||||
|
/**
|
||||||
|
* Waits till there are no more than 2 network connections for at least `500`
|
||||||
|
* ms.
|
||||||
|
*/
|
||||||
| 'networkidle2';
|
| 'networkidle2';
|
||||||
```
|
```
|
||||||
|
@ -12,7 +12,7 @@ export interface WaitForOptions
|
|||||||
|
|
||||||
## Properties
|
## Properties
|
||||||
|
|
||||||
| Property | Modifiers | Type | Description | Default |
|
| Property | Modifiers | Type | Description | Default |
|
||||||
| --------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------ |
|
| --------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------- |
|
||||||
| timeout | <code>optional</code> | number | <p>Maximum wait time in milliseconds. Pass 0 to disable the timeout.</p><p>The default value can be changed by using the [Page.setDefaultTimeout()](./puppeteer.page.setdefaulttimeout.md) or [Page.setDefaultNavigationTimeout()](./puppeteer.page.setdefaultnavigationtimeout.md) methods.</p> | <code>30000</code> |
|
| timeout | <code>optional</code> | number | <p>Maximum wait time in milliseconds. Pass 0 to disable the timeout.</p><p>The default value can be changed by using the [Page.setDefaultTimeout()](./puppeteer.page.setdefaulttimeout.md) or [Page.setDefaultNavigationTimeout()](./puppeteer.page.setdefaultnavigationtimeout.md) methods.</p> | <code>30000</code> |
|
||||||
| waitUntil | <code>optional</code> | [PuppeteerLifeCycleEvent](./puppeteer.puppeteerlifecycleevent.md) \| [PuppeteerLifeCycleEvent](./puppeteer.puppeteerlifecycleevent.md)\[\] | | |
|
| waitUntil | <code>optional</code> | [PuppeteerLifeCycleEvent](./puppeteer.puppeteerlifecycleevent.md) \| [PuppeteerLifeCycleEvent](./puppeteer.puppeteerlifecycleevent.md)\[\] | When to consider waiting succeeds. Given an array of event strings, waiting is considered to be successful after all events have been fired. | <code>'load'</code> |
|
||||||
|
@ -54,6 +54,45 @@ import {
|
|||||||
} from './locators/locators.js';
|
} from './locators/locators.js';
|
||||||
import {type Realm} from './Realm.js';
|
import {type Realm} from './Realm.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
export interface WaitForOptions {
|
||||||
|
/**
|
||||||
|
* Maximum wait time in milliseconds. Pass 0 to disable the timeout.
|
||||||
|
*
|
||||||
|
* The default value can be changed by using the
|
||||||
|
* {@link Page.setDefaultTimeout} or {@link Page.setDefaultNavigationTimeout}
|
||||||
|
* methods.
|
||||||
|
*
|
||||||
|
* @defaultValue `30000`
|
||||||
|
*/
|
||||||
|
timeout?: number;
|
||||||
|
/**
|
||||||
|
* When to consider waiting succeeds. Given an array of event strings, waiting
|
||||||
|
* is considered to be successful after all events have been fired.
|
||||||
|
*
|
||||||
|
* @defaultValue `'load'`
|
||||||
|
*/
|
||||||
|
waitUntil?: PuppeteerLifeCycleEvent | PuppeteerLifeCycleEvent[];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
export interface GoToOptions extends WaitForOptions {
|
||||||
|
/**
|
||||||
|
* If provided, it will take preference over the referer header value set by
|
||||||
|
* {@link Page.setExtraHTTPHeaders | page.setExtraHTTPHeaders()}.
|
||||||
|
*/
|
||||||
|
referer?: string;
|
||||||
|
/**
|
||||||
|
* If provided, it will take preference over the referer-policy header value
|
||||||
|
* set by {@link Page.setExtraHTTPHeaders | page.setExtraHTTPHeaders()}.
|
||||||
|
*/
|
||||||
|
referrerPolicy?: string;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
@ -278,7 +317,7 @@ export abstract class Frame extends EventEmitter<FrameEvents> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Navigates a frame to the given url.
|
* Navigates the frame to the given `url`.
|
||||||
*
|
*
|
||||||
* @remarks
|
* @remarks
|
||||||
* Navigation to `about:blank` or navigation to the same URL with a different
|
* Navigation to `about:blank` or navigation to the same URL with a different
|
||||||
@ -292,20 +331,17 @@ export abstract class Frame extends EventEmitter<FrameEvents> {
|
|||||||
*
|
*
|
||||||
* :::
|
* :::
|
||||||
*
|
*
|
||||||
* @param url - the URL to navigate the frame to. This should include the
|
* @param url - URL to navigate the frame to. The URL should include scheme,
|
||||||
* scheme, e.g. `https://`.
|
* e.g. `https://`
|
||||||
* @param options - navigation options. `waitUntil` is useful to define when
|
* @param options - Options to configure waiting behavior.
|
||||||
* the navigation should be considered successful - see the docs for
|
|
||||||
* {@link PuppeteerLifeCycleEvent} for more details.
|
|
||||||
*
|
|
||||||
* @returns A promise which resolves to the main resource response. In case of
|
* @returns A promise which resolves to the main resource response. In case of
|
||||||
* multiple redirects, the navigation will resolve with the response of the
|
* multiple redirects, the navigation will resolve with the response of the
|
||||||
* last redirect.
|
* last redirect.
|
||||||
* @throws This method will throw an error if:
|
* @throws If:
|
||||||
*
|
*
|
||||||
* - there's an SSL error (e.g. in case of self-signed certificates).
|
* - there's an SSL error (e.g. in case of self-signed certificates).
|
||||||
* - target URL is invalid.
|
* - target URL is invalid.
|
||||||
* - the `timeout` is exceeded during navigation.
|
* - the timeout is exceeded during navigation.
|
||||||
* - the remote server does not respond or is unreachable.
|
* - the remote server does not respond or is unreachable.
|
||||||
* - the main resource failed to load.
|
* - the main resource failed to load.
|
||||||
*
|
*
|
||||||
@ -343,14 +379,12 @@ export abstract class Frame extends EventEmitter<FrameEvents> {
|
|||||||
* ]);
|
* ]);
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* @param options - options to configure when the navigation is consided
|
* @param options - Options to configure waiting behavior.
|
||||||
* finished.
|
* @returns A promise which resolves to the main resource response.
|
||||||
* @returns a promise that resolves when the frame navigates to a new URL.
|
|
||||||
*/
|
*/
|
||||||
abstract waitForNavigation(options?: {
|
abstract waitForNavigation(
|
||||||
timeout?: number;
|
options?: WaitForOptions
|
||||||
waitUntil?: PuppeteerLifeCycleEvent | PuppeteerLifeCycleEvent[];
|
): Promise<HTTPResponse | null>;
|
||||||
}): Promise<HTTPResponse | null>;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
|
@ -28,11 +28,11 @@ import {
|
|||||||
fromEvent,
|
fromEvent,
|
||||||
map,
|
map,
|
||||||
merge,
|
merge,
|
||||||
type Observable,
|
|
||||||
of,
|
of,
|
||||||
raceWith,
|
raceWith,
|
||||||
startWith,
|
startWith,
|
||||||
switchMap,
|
switchMap,
|
||||||
|
type Observable,
|
||||||
} from '../../third_party/rxjs/rxjs.js';
|
} from '../../third_party/rxjs/rxjs.js';
|
||||||
import type {HTTPRequest} from '../api/HTTPRequest.js';
|
import type {HTTPRequest} from '../api/HTTPRequest.js';
|
||||||
import type {HTTPResponse} from '../api/HTTPResponse.js';
|
import type {HTTPResponse} from '../api/HTTPResponse.js';
|
||||||
@ -40,12 +40,11 @@ import type {BidiNetworkManager} from '../bidi/NetworkManager.js';
|
|||||||
import type {Accessibility} from '../cdp/Accessibility.js';
|
import type {Accessibility} from '../cdp/Accessibility.js';
|
||||||
import type {Coverage} from '../cdp/Coverage.js';
|
import type {Coverage} from '../cdp/Coverage.js';
|
||||||
import {type DeviceRequestPrompt} from '../cdp/DeviceRequestPrompt.js';
|
import {type DeviceRequestPrompt} from '../cdp/DeviceRequestPrompt.js';
|
||||||
import type {PuppeteerLifeCycleEvent} from '../cdp/LifecycleWatcher.js';
|
|
||||||
import {
|
import {
|
||||||
|
NetworkManagerEvent,
|
||||||
type NetworkManager as CdpNetworkManager,
|
type NetworkManager as CdpNetworkManager,
|
||||||
type Credentials,
|
type Credentials,
|
||||||
type NetworkConditions,
|
type NetworkConditions,
|
||||||
NetworkManagerEvent,
|
|
||||||
} from '../cdp/NetworkManager.js';
|
} from '../cdp/NetworkManager.js';
|
||||||
import type {Tracing} from '../cdp/Tracing.js';
|
import type {Tracing} from '../cdp/Tracing.js';
|
||||||
import type {WebWorker} from '../cdp/WebWorker.js';
|
import type {WebWorker} from '../cdp/WebWorker.js';
|
||||||
@ -60,8 +59,8 @@ import {
|
|||||||
} from '../common/EventEmitter.js';
|
} from '../common/EventEmitter.js';
|
||||||
import type {FileChooser} from '../common/FileChooser.js';
|
import type {FileChooser} from '../common/FileChooser.js';
|
||||||
import {
|
import {
|
||||||
type LowerCasePaperFormat,
|
|
||||||
paperFormats,
|
paperFormats,
|
||||||
|
type LowerCasePaperFormat,
|
||||||
type ParsedPDFOptions,
|
type ParsedPDFOptions,
|
||||||
type PDFOptions,
|
type PDFOptions,
|
||||||
} from '../common/PDFOptions.js';
|
} from '../common/PDFOptions.js';
|
||||||
@ -94,6 +93,8 @@ import type {
|
|||||||
FrameAddScriptTagOptions,
|
FrameAddScriptTagOptions,
|
||||||
FrameAddStyleTagOptions,
|
FrameAddStyleTagOptions,
|
||||||
FrameWaitForFunctionOptions,
|
FrameWaitForFunctionOptions,
|
||||||
|
GoToOptions,
|
||||||
|
WaitForOptions,
|
||||||
} from './Frame.js';
|
} from './Frame.js';
|
||||||
import {
|
import {
|
||||||
type Keyboard,
|
type Keyboard,
|
||||||
@ -103,10 +104,10 @@ import {
|
|||||||
} from './Input.js';
|
} from './Input.js';
|
||||||
import type {JSHandle} from './JSHandle.js';
|
import type {JSHandle} from './JSHandle.js';
|
||||||
import {
|
import {
|
||||||
type AwaitedLocator,
|
|
||||||
FunctionLocator,
|
FunctionLocator,
|
||||||
Locator,
|
Locator,
|
||||||
NodeLocator,
|
NodeLocator,
|
||||||
|
type AwaitedLocator,
|
||||||
} from './locators/locators.js';
|
} from './locators/locators.js';
|
||||||
import type {Target} from './Target.js';
|
import type {Target} from './Target.js';
|
||||||
|
|
||||||
@ -144,23 +145,6 @@ export interface WaitTimeoutOptions {
|
|||||||
timeout?: number;
|
timeout?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @public
|
|
||||||
*/
|
|
||||||
export interface WaitForOptions {
|
|
||||||
/**
|
|
||||||
* Maximum wait time in milliseconds. Pass 0 to disable the timeout.
|
|
||||||
*
|
|
||||||
* The default value can be changed by using the
|
|
||||||
* {@link Page.setDefaultTimeout} or {@link Page.setDefaultNavigationTimeout}
|
|
||||||
* methods.
|
|
||||||
*
|
|
||||||
* @defaultValue `30000`
|
|
||||||
*/
|
|
||||||
timeout?: number;
|
|
||||||
waitUntil?: PuppeteerLifeCycleEvent | PuppeteerLifeCycleEvent[];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
@ -1553,40 +1537,29 @@ export abstract class Page extends EventEmitter<PageEvents> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Navigates the page to the given `url`.
|
||||||
|
*
|
||||||
|
* @remarks
|
||||||
|
* Navigation to `about:blank` or navigation to the same URL with a different
|
||||||
|
* hash will succeed and return `null`.
|
||||||
|
*
|
||||||
|
* :::warning
|
||||||
|
*
|
||||||
|
* Headless mode doesn't support navigation to a PDF document. See the {@link
|
||||||
|
* https://bugs.chromium.org/p/chromium/issues/detail?id=761295 | upstream
|
||||||
|
* issue}.
|
||||||
|
*
|
||||||
|
* :::
|
||||||
|
*
|
||||||
|
* Shortcut for {@link Frame.goto | page.mainFrame().goto(url, options)}.
|
||||||
|
*
|
||||||
* @param url - URL to navigate page to. The URL should include scheme, e.g.
|
* @param url - URL to navigate page to. The URL should include scheme, e.g.
|
||||||
* `https://`
|
* `https://`
|
||||||
* @param options - Navigation Parameter
|
* @param options - Options to configure waiting behavior.
|
||||||
* @returns Promise which resolves to the main resource response. In case of
|
* @returns A promise which resolves to the main resource response. In case of
|
||||||
* multiple redirects, the navigation will resolve with the response of the
|
* multiple redirects, the navigation will resolve with the response of the
|
||||||
* last redirect.
|
* last redirect.
|
||||||
* @remarks
|
* @throws If:
|
||||||
* The argument `options` might have the following properties:
|
|
||||||
*
|
|
||||||
* - `timeout` : Maximum navigation time in milliseconds, defaults to 30
|
|
||||||
* seconds, pass 0 to disable timeout. The default value can be changed by
|
|
||||||
* using the {@link Page.setDefaultNavigationTimeout} or
|
|
||||||
* {@link Page.setDefaultTimeout} methods.
|
|
||||||
*
|
|
||||||
* - `waitUntil`:When to consider navigation succeeded, defaults to `load`.
|
|
||||||
* Given an array of event strings, navigation is considered to be
|
|
||||||
* successful after all events have been fired. Events can be either:<br/>
|
|
||||||
* - `load` : consider navigation to be finished when the load event is
|
|
||||||
* fired.<br/>
|
|
||||||
* - `domcontentloaded` : consider navigation to be finished when the
|
|
||||||
* DOMContentLoaded event is fired.<br/>
|
|
||||||
* - `networkidle0` : consider navigation to be finished when there are no
|
|
||||||
* more than 0 network connections for at least `500` ms.<br/>
|
|
||||||
* - `networkidle2` : consider navigation to be finished when there are no
|
|
||||||
* more than 2 network connections for at least `500` ms.
|
|
||||||
*
|
|
||||||
* - `referer` : Referer header value. If provided it will take preference
|
|
||||||
* over the referer header value set by
|
|
||||||
* {@link Page.setExtraHTTPHeaders |page.setExtraHTTPHeaders()}.<br/>
|
|
||||||
* - `referrerPolicy` : ReferrerPolicy. If provided it will take preference
|
|
||||||
* over the referer-policy header value set by
|
|
||||||
* {@link Page.setExtraHTTPHeaders |page.setExtraHTTPHeaders()}.
|
|
||||||
*
|
|
||||||
* `page.goto` will throw an error if:
|
|
||||||
*
|
*
|
||||||
* - there's an SSL error (e.g. in case of self-signed certificates).
|
* - there's an SSL error (e.g. in case of self-signed certificates).
|
||||||
* - target URL is invalid.
|
* - target URL is invalid.
|
||||||
@ -1594,53 +1567,22 @@ export abstract class Page extends EventEmitter<PageEvents> {
|
|||||||
* - the remote server does not respond or is unreachable.
|
* - the remote server does not respond or is unreachable.
|
||||||
* - the main resource failed to load.
|
* - the main resource failed to load.
|
||||||
*
|
*
|
||||||
* `page.goto` will not throw an error when any valid HTTP status code is
|
* This method will not throw an error when any valid HTTP status code is
|
||||||
* returned by the remote server, including 404 "Not Found" and 500
|
* returned by the remote server, including 404 "Not Found" and 500 "Internal
|
||||||
* "Internal Server Error". The status code for such responses can be
|
* Server Error". The status code for such responses can be retrieved by
|
||||||
* retrieved by calling response.status().
|
* calling {@link HTTPResponse.status}.
|
||||||
*
|
|
||||||
* NOTE: `page.goto` either throws an error or returns a main resource
|
|
||||||
* response. The only exceptions are navigation to about:blank or navigation
|
|
||||||
* to the same URL with a different hash, which would succeed and return null.
|
|
||||||
*
|
|
||||||
* NOTE: Headless mode doesn't support navigation to a PDF document. See the
|
|
||||||
* {@link https://bugs.chromium.org/p/chromium/issues/detail?id=761295 |
|
|
||||||
* upstream issue}.
|
|
||||||
*
|
|
||||||
* Shortcut for {@link Frame.goto | page.mainFrame().goto(url, options)}.
|
|
||||||
*/
|
*/
|
||||||
async goto(
|
async goto(url: string, options?: GoToOptions): Promise<HTTPResponse | null> {
|
||||||
url: string,
|
|
||||||
options?: WaitForOptions & {referer?: string; referrerPolicy?: string}
|
|
||||||
): Promise<HTTPResponse | null> {
|
|
||||||
return await this.mainFrame().goto(url, options);
|
return await this.mainFrame().goto(url, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param options - Navigation parameters which might have the following
|
* Reloads the page.
|
||||||
* properties:
|
*
|
||||||
* @returns Promise which resolves to the main resource response. In case of
|
* @param options - Options to configure waiting behavior.
|
||||||
|
* @returns A promise which resolves to the main resource response. In case of
|
||||||
* multiple redirects, the navigation will resolve with the response of the
|
* multiple redirects, the navigation will resolve with the response of the
|
||||||
* last redirect.
|
* last redirect.
|
||||||
* @remarks
|
|
||||||
* The argument `options` might have the following properties:
|
|
||||||
*
|
|
||||||
* - `timeout` : Maximum navigation time in milliseconds, defaults to 30
|
|
||||||
* seconds, pass 0 to disable timeout. The default value can be changed by
|
|
||||||
* using the {@link Page.setDefaultNavigationTimeout} or
|
|
||||||
* {@link Page.setDefaultTimeout} methods.
|
|
||||||
*
|
|
||||||
* - `waitUntil`: When to consider navigation succeeded, defaults to `load`.
|
|
||||||
* Given an array of event strings, navigation is considered to be
|
|
||||||
* successful after all events have been fired. Events can be either:<br/>
|
|
||||||
* - `load` : consider navigation to be finished when the load event is
|
|
||||||
* fired.<br/>
|
|
||||||
* - `domcontentloaded` : consider navigation to be finished when the
|
|
||||||
* DOMContentLoaded event is fired.<br/>
|
|
||||||
* - `networkidle0` : consider navigation to be finished when there are no
|
|
||||||
* more than 0 network connections for at least `500` ms.<br/>
|
|
||||||
* - `networkidle2` : consider navigation to be finished when there are no
|
|
||||||
* more than 2 network connections for at least `500` ms.
|
|
||||||
*/
|
*/
|
||||||
async reload(options?: WaitForOptions): Promise<HTTPResponse | null>;
|
async reload(options?: WaitForOptions): Promise<HTTPResponse | null>;
|
||||||
async reload(): Promise<HTTPResponse | null> {
|
async reload(): Promise<HTTPResponse | null> {
|
||||||
|
@ -1,17 +1,11 @@
|
|||||||
import * as Bidi from 'chromium-bidi/lib/cjs/protocol/protocol.js';
|
import type * as Bidi from 'chromium-bidi/lib/cjs/protocol/protocol.js';
|
||||||
import type ProtocolMapping from 'devtools-protocol/types/protocol-mapping.js';
|
import type ProtocolMapping from 'devtools-protocol/types/protocol-mapping.js';
|
||||||
|
|
||||||
import {CDPSession} from '../api/CDPSession.js';
|
import {CDPSession} from '../api/CDPSession.js';
|
||||||
import {type WaitForOptions} from '../api/Page.js';
|
|
||||||
import {type Connection as CdpConnection} from '../cdp/Connection.js';
|
import {type Connection as CdpConnection} from '../cdp/Connection.js';
|
||||||
import {type PuppeteerLifeCycleEvent} from '../cdp/LifecycleWatcher.js';
|
import {type PuppeteerLifeCycleEvent} from '../cdp/LifecycleWatcher.js';
|
||||||
import {
|
import {TargetCloseError} from '../common/Errors.js';
|
||||||
ProtocolError,
|
|
||||||
TargetCloseError,
|
|
||||||
TimeoutError,
|
|
||||||
} from '../common/Errors.js';
|
|
||||||
import {type EventType} from '../common/EventEmitter.js';
|
import {type EventType} from '../common/EventEmitter.js';
|
||||||
import {setPageContent, waitWithTimeout} from '../common/util.js';
|
|
||||||
import {assert} from '../util/assert.js';
|
import {assert} from '../util/assert.js';
|
||||||
import {Deferred} from '../util/Deferred.js';
|
import {Deferred} from '../util/Deferred.js';
|
||||||
|
|
||||||
@ -30,17 +24,6 @@ export const lifeCycleToSubscribedEvent = new Map<
|
|||||||
['domcontentloaded', 'browsingContext.domContentLoaded'],
|
['domcontentloaded', 'browsingContext.domContentLoaded'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
const lifeCycleToReadinessState = new Map<
|
|
||||||
PuppeteerLifeCycleEvent,
|
|
||||||
Bidi.BrowsingContext.ReadinessState
|
|
||||||
>([
|
|
||||||
['load', Bidi.BrowsingContext.ReadinessState.Complete],
|
|
||||||
['domcontentloaded', Bidi.BrowsingContext.ReadinessState.Interactive],
|
|
||||||
]);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
@ -202,101 +185,6 @@ export class BrowsingContext extends BidiRealm {
|
|||||||
return this.#cdpSession;
|
return this.#cdpSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
async goto(
|
|
||||||
url: string,
|
|
||||||
options: {
|
|
||||||
referer?: string;
|
|
||||||
referrerPolicy?: string;
|
|
||||||
timeout: number;
|
|
||||||
waitUntil?: PuppeteerLifeCycleEvent | PuppeteerLifeCycleEvent[];
|
|
||||||
}
|
|
||||||
): Promise<string | null> {
|
|
||||||
const {waitUntil = 'load', timeout} = options;
|
|
||||||
|
|
||||||
const readinessState = lifeCycleToReadinessState.get(
|
|
||||||
getWaitUntilSingle(waitUntil)
|
|
||||||
) as Bidi.BrowsingContext.ReadinessState;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const {result} = await waitWithTimeout(
|
|
||||||
this.connection.send('browsingContext.navigate', {
|
|
||||||
url: url,
|
|
||||||
context: this.#id,
|
|
||||||
wait: readinessState,
|
|
||||||
}),
|
|
||||||
'Navigation',
|
|
||||||
timeout
|
|
||||||
);
|
|
||||||
this.#url = result.url;
|
|
||||||
|
|
||||||
return result.navigation;
|
|
||||||
} catch (error) {
|
|
||||||
if (error instanceof ProtocolError) {
|
|
||||||
error.message += ` at ${url}`;
|
|
||||||
} else if (error instanceof TimeoutError) {
|
|
||||||
error.message = 'Navigation timeout of ' + timeout + ' ms exceeded';
|
|
||||||
}
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async reload(
|
|
||||||
options: WaitForOptions & {timeout: number}
|
|
||||||
): Promise<string | null> {
|
|
||||||
const {waitUntil = 'load', timeout} = options;
|
|
||||||
|
|
||||||
const readinessState = lifeCycleToReadinessState.get(
|
|
||||||
getWaitUntilSingle(waitUntil)
|
|
||||||
) as Bidi.BrowsingContext.ReadinessState;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const {result} = await waitWithTimeout(
|
|
||||||
this.connection.send('browsingContext.reload', {
|
|
||||||
context: this.#id,
|
|
||||||
wait: readinessState,
|
|
||||||
}),
|
|
||||||
'Navigation',
|
|
||||||
timeout
|
|
||||||
);
|
|
||||||
|
|
||||||
return result.navigation;
|
|
||||||
} catch (error) {
|
|
||||||
if (error instanceof ProtocolError) {
|
|
||||||
error.message += ` at ${this.url}`;
|
|
||||||
} else if (error instanceof TimeoutError) {
|
|
||||||
error.message = 'Navigation timeout of ' + timeout + ' ms exceeded';
|
|
||||||
}
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async setContent(
|
|
||||||
html: string,
|
|
||||||
options: {
|
|
||||||
timeout: number;
|
|
||||||
waitUntil?: PuppeteerLifeCycleEvent | PuppeteerLifeCycleEvent[];
|
|
||||||
}
|
|
||||||
): Promise<void> {
|
|
||||||
const {waitUntil = 'load', timeout} = options;
|
|
||||||
|
|
||||||
const waitUntilEvent = lifeCycleToSubscribedEvent.get(
|
|
||||||
getWaitUntilSingle(waitUntil)
|
|
||||||
) as string;
|
|
||||||
|
|
||||||
await Promise.all([
|
|
||||||
setPageContent(this, html),
|
|
||||||
waitWithTimeout(
|
|
||||||
new Promise<void>(resolve => {
|
|
||||||
this.once(waitUntilEvent, () => {
|
|
||||||
resolve();
|
|
||||||
});
|
|
||||||
}),
|
|
||||||
waitUntilEvent,
|
|
||||||
timeout
|
|
||||||
),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
async sendCdpCommand<T extends keyof ProtocolMapping.Commands>(
|
async sendCdpCommand<T extends keyof ProtocolMapping.Commands>(
|
||||||
method: T,
|
method: T,
|
||||||
...paramArgs: ProtocolMapping.Commands[T]['paramsType']
|
...paramArgs: ProtocolMapping.Commands[T]['paramsType']
|
||||||
@ -304,12 +192,6 @@ export class BrowsingContext extends BidiRealm {
|
|||||||
return await this.#cdpSession.send(method, ...paramArgs);
|
return await this.#cdpSession.send(method, ...paramArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
title(): Promise<string> {
|
|
||||||
return this.evaluate(() => {
|
|
||||||
return document.title;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
dispose(): void {
|
dispose(): void {
|
||||||
this.removeAllListeners();
|
this.removeAllListeners();
|
||||||
this.connection.unregisterBrowsingContexts(this.#id);
|
this.connection.unregisterBrowsingContexts(this.#id);
|
||||||
|
@ -17,17 +17,28 @@
|
|||||||
import * as Bidi from 'chromium-bidi/lib/cjs/protocol/protocol.js';
|
import * as Bidi from 'chromium-bidi/lib/cjs/protocol/protocol.js';
|
||||||
|
|
||||||
import {type CDPSession} from '../api/CDPSession.js';
|
import {type CDPSession} from '../api/CDPSession.js';
|
||||||
import {Frame, throwIfDetached} from '../api/Frame.js';
|
import {
|
||||||
|
Frame,
|
||||||
|
type GoToOptions,
|
||||||
|
type WaitForOptions,
|
||||||
|
throwIfDetached,
|
||||||
|
} from '../api/Frame.js';
|
||||||
import {type PuppeteerLifeCycleEvent} from '../cdp/LifecycleWatcher.js';
|
import {type PuppeteerLifeCycleEvent} from '../cdp/LifecycleWatcher.js';
|
||||||
|
import {ProtocolError, TimeoutError} from '../common/Errors.js';
|
||||||
import {type TimeoutSettings} from '../common/TimeoutSettings.js';
|
import {type TimeoutSettings} from '../common/TimeoutSettings.js';
|
||||||
import {type Awaitable} from '../common/types.js';
|
import {type Awaitable} from '../common/types.js';
|
||||||
import {UTILITY_WORLD_NAME, waitForEvent} from '../common/util.js';
|
import {
|
||||||
|
UTILITY_WORLD_NAME,
|
||||||
|
setPageContent,
|
||||||
|
waitForEvent,
|
||||||
|
waitWithTimeout,
|
||||||
|
} from '../common/util.js';
|
||||||
import {Deferred} from '../util/Deferred.js';
|
import {Deferred} from '../util/Deferred.js';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
type BrowsingContext,
|
|
||||||
getWaitUntilSingle,
|
getWaitUntilSingle,
|
||||||
lifeCycleToSubscribedEvent,
|
lifeCycleToSubscribedEvent,
|
||||||
|
type BrowsingContext,
|
||||||
} from './BrowsingContext.js';
|
} from './BrowsingContext.js';
|
||||||
import {ExposeableFunction} from './ExposedFunction.js';
|
import {ExposeableFunction} from './ExposedFunction.js';
|
||||||
import {type BidiHTTPResponse} from './HTTPResponse.js';
|
import {type BidiHTTPResponse} from './HTTPResponse.js';
|
||||||
@ -39,6 +50,17 @@ import {
|
|||||||
type SandboxChart,
|
type SandboxChart,
|
||||||
} from './Sandbox.js';
|
} from './Sandbox.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
export const lifeCycleToReadinessState = new Map<
|
||||||
|
PuppeteerLifeCycleEvent,
|
||||||
|
Bidi.BrowsingContext.ReadinessState
|
||||||
|
>([
|
||||||
|
['load', Bidi.BrowsingContext.ReadinessState.Complete],
|
||||||
|
['domcontentloaded', Bidi.BrowsingContext.ReadinessState.Interactive],
|
||||||
|
]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Puppeteer's Frame class could be viewed as a BiDi BrowsingContext implementation
|
* Puppeteer's Frame class could be viewed as a BiDi BrowsingContext implementation
|
||||||
* @internal
|
* @internal
|
||||||
@ -107,32 +129,65 @@ export class BidiFrame extends Frame {
|
|||||||
@throwIfDetached
|
@throwIfDetached
|
||||||
override async goto(
|
override async goto(
|
||||||
url: string,
|
url: string,
|
||||||
options?: {
|
options: GoToOptions = {}
|
||||||
referer?: string;
|
|
||||||
referrerPolicy?: string;
|
|
||||||
timeout?: number;
|
|
||||||
waitUntil?: PuppeteerLifeCycleEvent | PuppeteerLifeCycleEvent[];
|
|
||||||
}
|
|
||||||
): Promise<BidiHTTPResponse | null> {
|
): Promise<BidiHTTPResponse | null> {
|
||||||
const navigationId = await this.#context.goto(url, {
|
const {
|
||||||
...options,
|
waitUntil = 'load',
|
||||||
timeout: options?.timeout ?? this.#timeoutSettings.navigationTimeout(),
|
timeout = this.#timeoutSettings.navigationTimeout(),
|
||||||
});
|
} = options;
|
||||||
return this.#page.getNavigationResponse(navigationId);
|
|
||||||
|
const readinessState = lifeCycleToReadinessState.get(
|
||||||
|
getWaitUntilSingle(waitUntil)
|
||||||
|
) as Bidi.BrowsingContext.ReadinessState;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const {result} = await waitWithTimeout(
|
||||||
|
this.#context.connection.send('browsingContext.navigate', {
|
||||||
|
url: url,
|
||||||
|
context: this._id,
|
||||||
|
wait: readinessState,
|
||||||
|
}),
|
||||||
|
'Navigation',
|
||||||
|
timeout
|
||||||
|
);
|
||||||
|
|
||||||
|
return this.#page.getNavigationResponse(result.navigation);
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof ProtocolError) {
|
||||||
|
error.message += ` at ${url}`;
|
||||||
|
} else if (error instanceof TimeoutError) {
|
||||||
|
error.message = 'Navigation timeout of ' + timeout + ' ms exceeded';
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@throwIfDetached
|
@throwIfDetached
|
||||||
override setContent(
|
override async setContent(
|
||||||
html: string,
|
html: string,
|
||||||
options: {
|
options: WaitForOptions = {}
|
||||||
timeout?: number;
|
|
||||||
waitUntil?: PuppeteerLifeCycleEvent | PuppeteerLifeCycleEvent[];
|
|
||||||
}
|
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
return this.#context.setContent(html, {
|
const {
|
||||||
...options,
|
waitUntil = 'load',
|
||||||
timeout: options?.timeout ?? this.#timeoutSettings.navigationTimeout(),
|
timeout = this.#timeoutSettings.navigationTimeout(),
|
||||||
});
|
} = options;
|
||||||
|
|
||||||
|
const waitUntilEvent = lifeCycleToSubscribedEvent.get(
|
||||||
|
getWaitUntilSingle(waitUntil)
|
||||||
|
) as string;
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
setPageContent(this, html),
|
||||||
|
waitWithTimeout(
|
||||||
|
new Promise<void>(resolve => {
|
||||||
|
this.#context.once(waitUntilEvent, () => {
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
waitUntilEvent,
|
||||||
|
timeout
|
||||||
|
),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
context(): BrowsingContext {
|
context(): BrowsingContext {
|
||||||
@ -141,10 +196,7 @@ export class BidiFrame extends Frame {
|
|||||||
|
|
||||||
@throwIfDetached
|
@throwIfDetached
|
||||||
override async waitForNavigation(
|
override async waitForNavigation(
|
||||||
options: {
|
options: WaitForOptions = {}
|
||||||
timeout?: number;
|
|
||||||
waitUntil?: PuppeteerLifeCycleEvent | PuppeteerLifeCycleEvent[];
|
|
||||||
} = {}
|
|
||||||
): Promise<BidiHTTPResponse | null> {
|
): Promise<BidiHTTPResponse | null> {
|
||||||
const {
|
const {
|
||||||
waitUntil = 'load',
|
waitUntil = 'load',
|
||||||
|
@ -20,14 +20,14 @@ import type * as Bidi from 'chromium-bidi/lib/cjs/protocol/protocol.js';
|
|||||||
import type Protocol from 'devtools-protocol';
|
import type Protocol from 'devtools-protocol';
|
||||||
|
|
||||||
import {type CDPSession} from '../api/CDPSession.js';
|
import {type CDPSession} from '../api/CDPSession.js';
|
||||||
|
import {type WaitForOptions} from '../api/Frame.js';
|
||||||
import {
|
import {
|
||||||
|
Page,
|
||||||
|
PageEvent,
|
||||||
type GeolocationOptions,
|
type GeolocationOptions,
|
||||||
type MediaFeature,
|
type MediaFeature,
|
||||||
type NewDocumentScriptEvaluation,
|
type NewDocumentScriptEvaluation,
|
||||||
Page,
|
|
||||||
PageEvent,
|
|
||||||
type ScreenshotOptions,
|
type ScreenshotOptions,
|
||||||
type WaitForOptions,
|
|
||||||
} from '../api/Page.js';
|
} from '../api/Page.js';
|
||||||
import {Accessibility} from '../cdp/Accessibility.js';
|
import {Accessibility} from '../cdp/Accessibility.js';
|
||||||
import {Coverage} from '../cdp/Coverage.js';
|
import {Coverage} from '../cdp/Coverage.js';
|
||||||
@ -39,7 +39,11 @@ import {
|
|||||||
ConsoleMessage,
|
ConsoleMessage,
|
||||||
type ConsoleMessageLocation,
|
type ConsoleMessageLocation,
|
||||||
} from '../common/ConsoleMessage.js';
|
} from '../common/ConsoleMessage.js';
|
||||||
import {TargetCloseError} from '../common/Errors.js';
|
import {
|
||||||
|
ProtocolError,
|
||||||
|
TargetCloseError,
|
||||||
|
TimeoutError,
|
||||||
|
} from '../common/Errors.js';
|
||||||
import {type Handler} from '../common/EventEmitter.js';
|
import {type Handler} from '../common/EventEmitter.js';
|
||||||
import {type PDFOptions} from '../common/PDFOptions.js';
|
import {type PDFOptions} from '../common/PDFOptions.js';
|
||||||
import {TimeoutSettings} from '../common/TimeoutSettings.js';
|
import {TimeoutSettings} from '../common/TimeoutSettings.js';
|
||||||
@ -59,14 +63,15 @@ import {Deferred} from '../util/Deferred.js';
|
|||||||
import {type BidiBrowser} from './Browser.js';
|
import {type BidiBrowser} from './Browser.js';
|
||||||
import {type BidiBrowserContext} from './BrowserContext.js';
|
import {type BidiBrowserContext} from './BrowserContext.js';
|
||||||
import {
|
import {
|
||||||
type BrowsingContext,
|
|
||||||
BrowsingContextEvent,
|
BrowsingContextEvent,
|
||||||
CdpSessionWrapper,
|
CdpSessionWrapper,
|
||||||
|
getWaitUntilSingle,
|
||||||
|
type BrowsingContext,
|
||||||
} from './BrowsingContext.js';
|
} from './BrowsingContext.js';
|
||||||
import {type BidiConnection} from './Connection.js';
|
import {type BidiConnection} from './Connection.js';
|
||||||
import {BidiDialog} from './Dialog.js';
|
import {BidiDialog} from './Dialog.js';
|
||||||
import {EmulationManager} from './EmulationManager.js';
|
import {EmulationManager} from './EmulationManager.js';
|
||||||
import {BidiFrame} from './Frame.js';
|
import {BidiFrame, lifeCycleToReadinessState} from './Frame.js';
|
||||||
import {type BidiHTTPRequest} from './HTTPRequest.js';
|
import {type BidiHTTPRequest} from './HTTPRequest.js';
|
||||||
import {type BidiHTTPResponse} from './HTTPResponse.js';
|
import {type BidiHTTPResponse} from './HTTPResponse.js';
|
||||||
import {BidiKeyboard, BidiMouse, BidiTouchscreen} from './Input.js';
|
import {BidiKeyboard, BidiMouse, BidiTouchscreen} from './Input.js';
|
||||||
@ -414,15 +419,36 @@ export class BidiPage extends Page {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override async reload(
|
override async reload(
|
||||||
options?: WaitForOptions
|
options: WaitForOptions = {}
|
||||||
): Promise<BidiHTTPResponse | null> {
|
): Promise<BidiHTTPResponse | null> {
|
||||||
const navigationId = await this.mainFrame()
|
const {
|
||||||
.context()
|
waitUntil = 'load',
|
||||||
.reload({
|
timeout = this.#timeoutSettings.navigationTimeout(),
|
||||||
...options,
|
} = options;
|
||||||
timeout: options?.timeout ?? this.#timeoutSettings.navigationTimeout(),
|
|
||||||
});
|
const readinessState = lifeCycleToReadinessState.get(
|
||||||
return this.getNavigationResponse(navigationId);
|
getWaitUntilSingle(waitUntil)
|
||||||
|
) as Bidi.BrowsingContext.ReadinessState;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const {result} = await waitWithTimeout(
|
||||||
|
this.#connection.send('browsingContext.reload', {
|
||||||
|
context: this.mainFrame()._id,
|
||||||
|
wait: readinessState,
|
||||||
|
}),
|
||||||
|
'Navigation',
|
||||||
|
timeout
|
||||||
|
);
|
||||||
|
|
||||||
|
return this.getNavigationResponse(result.navigation);
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof ProtocolError) {
|
||||||
|
error.message += ` at ${this.url}`;
|
||||||
|
} else if (error instanceof TimeoutError) {
|
||||||
|
error.message = 'Navigation timeout of ' + timeout + ' ms exceeded';
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override setDefaultNavigationTimeout(timeout: number): void {
|
override setDefaultNavigationTimeout(timeout: number): void {
|
||||||
|
@ -27,13 +27,28 @@ import {type CdpFrame} from './Frame.js';
|
|||||||
import {FrameManagerEvent} from './FrameManager.js';
|
import {FrameManagerEvent} from './FrameManager.js';
|
||||||
import {type CdpHTTPRequest} from './HTTPRequest.js';
|
import {type CdpHTTPRequest} from './HTTPRequest.js';
|
||||||
import {type NetworkManager, NetworkManagerEvent} from './NetworkManager.js';
|
import {type NetworkManager, NetworkManagerEvent} from './NetworkManager.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
export type PuppeteerLifeCycleEvent =
|
export type PuppeteerLifeCycleEvent =
|
||||||
|
/**
|
||||||
|
* Waits for the 'load' event.
|
||||||
|
*/
|
||||||
| 'load'
|
| 'load'
|
||||||
|
/**
|
||||||
|
* Waits for the 'DOMContentLoaded' event.
|
||||||
|
*/
|
||||||
| 'domcontentloaded'
|
| 'domcontentloaded'
|
||||||
|
/**
|
||||||
|
* Waits till there are no more than 0 network connections for at least `500`
|
||||||
|
* ms.
|
||||||
|
*/
|
||||||
| 'networkidle0'
|
| 'networkidle0'
|
||||||
|
/**
|
||||||
|
* Waits till there are no more than 2 network connections for at least `500`
|
||||||
|
* ms.
|
||||||
|
*/
|
||||||
| 'networkidle2';
|
| 'networkidle2';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,22 +20,21 @@ import {Protocol} from 'devtools-protocol';
|
|||||||
|
|
||||||
import type {Browser} from '../api/Browser.js';
|
import type {Browser} from '../api/Browser.js';
|
||||||
import type {BrowserContext} from '../api/BrowserContext.js';
|
import type {BrowserContext} from '../api/BrowserContext.js';
|
||||||
import {type CDPSession, CDPSessionEvent} from '../api/CDPSession.js';
|
import {CDPSessionEvent, type CDPSession} from '../api/CDPSession.js';
|
||||||
import {type ElementHandle} from '../api/ElementHandle.js';
|
import {type ElementHandle} from '../api/ElementHandle.js';
|
||||||
import {type Frame} from '../api/Frame.js';
|
import {type WaitForOptions, type Frame} from '../api/Frame.js';
|
||||||
import {type HTTPRequest} from '../api/HTTPRequest.js';
|
import {type HTTPRequest} from '../api/HTTPRequest.js';
|
||||||
import {type HTTPResponse} from '../api/HTTPResponse.js';
|
import {type HTTPResponse} from '../api/HTTPResponse.js';
|
||||||
import {type JSHandle} from '../api/JSHandle.js';
|
import {type JSHandle} from '../api/JSHandle.js';
|
||||||
import {
|
import {
|
||||||
|
Page,
|
||||||
|
PageEvent,
|
||||||
type GeolocationOptions,
|
type GeolocationOptions,
|
||||||
type MediaFeature,
|
type MediaFeature,
|
||||||
type Metrics,
|
type Metrics,
|
||||||
type NewDocumentScriptEvaluation,
|
type NewDocumentScriptEvaluation,
|
||||||
Page,
|
|
||||||
PageEvent,
|
|
||||||
type ScreenshotClip,
|
type ScreenshotClip,
|
||||||
type ScreenshotOptions,
|
type ScreenshotOptions,
|
||||||
type WaitForOptions,
|
|
||||||
type WaitTimeoutOptions,
|
type WaitTimeoutOptions,
|
||||||
} from '../api/Page.js';
|
} from '../api/Page.js';
|
||||||
import {
|
import {
|
||||||
@ -80,9 +79,9 @@ import {FrameManager, FrameManagerEvent} from './FrameManager.js';
|
|||||||
import {CdpKeyboard, CdpMouse, CdpTouchscreen} from './Input.js';
|
import {CdpKeyboard, CdpMouse, CdpTouchscreen} from './Input.js';
|
||||||
import {MAIN_WORLD} from './IsolatedWorlds.js';
|
import {MAIN_WORLD} from './IsolatedWorlds.js';
|
||||||
import {
|
import {
|
||||||
|
NetworkManagerEvent,
|
||||||
type Credentials,
|
type Credentials,
|
||||||
type NetworkConditions,
|
type NetworkConditions,
|
||||||
NetworkManagerEvent,
|
|
||||||
} from './NetworkManager.js';
|
} from './NetworkManager.js';
|
||||||
import {type CdpTarget} from './Target.js';
|
import {type CdpTarget} from './Target.js';
|
||||||
import {TargetManagerEvent} from './TargetManager.js';
|
import {TargetManagerEvent} from './TargetManager.js';
|
||||||
@ -865,12 +864,12 @@ export class CdpPage extends Page {
|
|||||||
override async reload(
|
override async reload(
|
||||||
options?: WaitForOptions
|
options?: WaitForOptions
|
||||||
): Promise<HTTPResponse | null> {
|
): Promise<HTTPResponse | null> {
|
||||||
const result = await Promise.all([
|
const [result] = await Promise.all([
|
||||||
this.waitForNavigation(options),
|
this.waitForNavigation(options),
|
||||||
this.#client.send('Page.reload'),
|
this.#client.send('Page.reload'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return result[0];
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
override async createCDPSession(): Promise<CDPSession> {
|
override async createCDPSession(): Promise<CDPSession> {
|
||||||
|
Loading…
Reference in New Issue
Block a user