api(networkidle): remove networkidle2 (#1883)
This commit is contained in:
parent
1dff8e818a
commit
0656771167
|
|
@ -46,6 +46,7 @@
|
||||||
- [Travis CI](./ci.md#travis-ci)
|
- [Travis CI](./ci.md#travis-ci)
|
||||||
- [CircleCI](./ci.md#circleci)
|
- [CircleCI](./ci.md#circleci)
|
||||||
- [AppVeyor](./ci.md#appveyor)
|
- [AppVeyor](./ci.md#appveyor)
|
||||||
|
- Troubleshooting
|
||||||
1. Test runners
|
1. Test runners
|
||||||
- Jest
|
- Jest
|
||||||
- Mocha
|
- Mocha
|
||||||
|
|
|
||||||
55
docs/api.md
55
docs/api.md
|
|
@ -1242,11 +1242,10 @@ Returns frame matching the specified criteria. Either `name` or `url` must be sp
|
||||||
#### page.goBack([options])
|
#### page.goBack([options])
|
||||||
- `options` <[Object]> Navigation parameters which might have the following properties:
|
- `options` <[Object]> Navigation parameters which might have the following properties:
|
||||||
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultNavigationTimeout(timeout)](#browsercontextsetdefaultnavigationtimeouttimeout), [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout), [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
|
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultNavigationTimeout(timeout)](#browsercontextsetdefaultnavigationtimeouttimeout), [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout), [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
|
||||||
- `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"> When to consider navigation succeeded, defaults to `load`. Events can be either:
|
- `waitUntil` <"load"|"domcontentloaded"|"networkidle"> When to consider navigation succeeded, defaults to `load`. Events can be either:
|
||||||
- `'domcontentloaded'` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
|
- `'domcontentloaded'` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
|
||||||
- `'load'` - consider navigation to be finished when the `load` event is fired.
|
- `'load'` - consider navigation to be finished when the `load` event is fired.
|
||||||
- `'networkidle0'` - consider navigation to be finished when there are no more than 0 network connections for at least `500` ms.
|
- `'networkidle'` - consider navigation to be finished when there are no network connections for at least `500` ms.
|
||||||
- `'networkidle2'` - consider navigation to be finished when there are no more than 2 network connections for at least `500` ms.
|
|
||||||
- returns: <[Promise]<?[Response]>> Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect. If
|
- returns: <[Promise]<?[Response]>> Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect. If
|
||||||
can not go back, resolves to `null`.
|
can not go back, resolves to `null`.
|
||||||
|
|
||||||
|
|
@ -1255,11 +1254,10 @@ Navigate to the previous page in history.
|
||||||
#### page.goForward([options])
|
#### page.goForward([options])
|
||||||
- `options` <[Object]> Navigation parameters which might have the following properties:
|
- `options` <[Object]> Navigation parameters which might have the following properties:
|
||||||
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultNavigationTimeout(timeout)](#browsercontextsetdefaultnavigationtimeouttimeout), [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout), [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
|
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultNavigationTimeout(timeout)](#browsercontextsetdefaultnavigationtimeouttimeout), [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout), [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
|
||||||
- `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"> When to consider navigation succeeded, defaults to `load`. Events can be either:
|
- `waitUntil` <"load"|"domcontentloaded"|"networkidle"> When to consider navigation succeeded, defaults to `load`. Events can be either:
|
||||||
- `'domcontentloaded'` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
|
- `'domcontentloaded'` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
|
||||||
- `'load'` - consider navigation to be finished when the `load` event is fired.
|
- `'load'` - consider navigation to be finished when the `load` event is fired.
|
||||||
- `'networkidle0'` - consider navigation to be finished when there are no more than 0 network connections for at least `500` ms.
|
- `'networkidle'` - consider navigation to be finished when there are no network connections for at least `500` ms.
|
||||||
- `'networkidle2'` - consider navigation to be finished when there are no more than 2 network connections for at least `500` ms.
|
|
||||||
- returns: <[Promise]<?[Response]>> Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect. If
|
- returns: <[Promise]<?[Response]>> Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect. If
|
||||||
can not go forward, resolves to `null`.
|
can not go forward, resolves to `null`.
|
||||||
|
|
||||||
|
|
@ -1269,11 +1267,10 @@ Navigate to the next page in history.
|
||||||
- `url` <[string]> URL to navigate page to. The url should include scheme, e.g. `https://`.
|
- `url` <[string]> URL to navigate page to. The url should include scheme, e.g. `https://`.
|
||||||
- `options` <[Object]> Navigation parameters which might have the following properties:
|
- `options` <[Object]> Navigation parameters which might have the following properties:
|
||||||
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultNavigationTimeout(timeout)](#browsercontextsetdefaultnavigationtimeouttimeout), [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout), [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
|
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultNavigationTimeout(timeout)](#browsercontextsetdefaultnavigationtimeouttimeout), [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout), [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
|
||||||
- `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"> When to consider navigation succeeded, defaults to `load`. Events can be either:
|
- `waitUntil` <"load"|"domcontentloaded"|"networkidle"> When to consider navigation succeeded, defaults to `load`. Events can be either:
|
||||||
- `'domcontentloaded'` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
|
- `'domcontentloaded'` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
|
||||||
- `'load'` - consider navigation to be finished when the `load` event is fired.
|
- `'load'` - consider navigation to be finished when the `load` event is fired.
|
||||||
- `'networkidle0'` - consider navigation to be finished when there are no more than 0 network connections for at least `500` ms.
|
- `'networkidle'` - consider navigation to be finished when there are no network connections for at least `500` ms.
|
||||||
- `'networkidle2'` - consider navigation to be finished when there are no more than 2 network connections for at least `500` ms.
|
|
||||||
- `referer` <[string]> Referer header value. If provided it will take preference over the referer header value set by [page.setExtraHTTPHeaders()](#pagesetextrahttpheadersheaders).
|
- `referer` <[string]> Referer header value. If provided it will take preference over the referer header value set by [page.setExtraHTTPHeaders()](#pagesetextrahttpheadersheaders).
|
||||||
- returns: <[Promise]<?[Response]>> Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect.
|
- returns: <[Promise]<?[Response]>> Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect.
|
||||||
|
|
||||||
|
|
@ -1441,11 +1438,10 @@ await browser.close();
|
||||||
#### page.reload([options])
|
#### page.reload([options])
|
||||||
- `options` <[Object]> Navigation parameters which might have the following properties:
|
- `options` <[Object]> Navigation parameters which might have the following properties:
|
||||||
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultNavigationTimeout(timeout)](#browsercontextsetdefaultnavigationtimeouttimeout), [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout), [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
|
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultNavigationTimeout(timeout)](#browsercontextsetdefaultnavigationtimeouttimeout), [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout), [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
|
||||||
- `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"> When to consider navigation succeeded, defaults to `load`. Events can be either:
|
- `waitUntil` <"load"|"domcontentloaded"|"networkidle"> When to consider navigation succeeded, defaults to `load`. Events can be either:
|
||||||
- `'domcontentloaded'` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
|
- `'domcontentloaded'` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
|
||||||
- `'load'` - consider navigation to be finished when the `load` event is fired.
|
- `'load'` - consider navigation to be finished when the `load` event is fired.
|
||||||
- `'networkidle0'` - consider navigation to be finished when there are no more than 0 network connections for at least `500` ms.
|
- `'networkidle'` - consider navigation to be finished when there are no network connections for at least `500` ms.
|
||||||
- `'networkidle2'` - consider navigation to be finished when there are no more than 2 network connections for at least `500` ms.
|
|
||||||
- returns: <[Promise]<?[Response]>> Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect.
|
- returns: <[Promise]<?[Response]>> Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect.
|
||||||
|
|
||||||
#### page.route(url, handler)
|
#### page.route(url, handler)
|
||||||
|
|
@ -1527,11 +1523,10 @@ Shortcut for [page.mainFrame().selectOption()](#frameselectoptionselector-values
|
||||||
- `html` <[string]> HTML markup to assign to the page.
|
- `html` <[string]> HTML markup to assign to the page.
|
||||||
- `options` <[Object]> Parameters which might have the following properties:
|
- `options` <[Object]> Parameters which might have the following properties:
|
||||||
- `timeout` <[number]> Maximum time in milliseconds for resources to load, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultNavigationTimeout(timeout)](#browsercontextsetdefaultnavigationtimeouttimeout), [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout), [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
|
- `timeout` <[number]> Maximum time in milliseconds for resources to load, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultNavigationTimeout(timeout)](#browsercontextsetdefaultnavigationtimeouttimeout), [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout), [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
|
||||||
- `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"> When to consider setting markup succeeded, defaults to `load`. Given an array of event strings, setting content is considered to be successful after all events have been fired. Events can be either:
|
- `waitUntil` <"load"|"domcontentloaded"|"networkidle"> When to consider setting markup succeeded, defaults to `load`. Given an array of event strings, setting content is considered to be successful after all events have been fired. Events can be either:
|
||||||
- `'load'` - consider setting content to be finished when the `load` event is fired.
|
- `'load'` - consider setting content to be finished when the `load` event is fired.
|
||||||
- `'domcontentloaded'` - consider setting content to be finished when the `DOMContentLoaded` event is fired.
|
- `'domcontentloaded'` - consider setting content to be finished when the `DOMContentLoaded` event is fired.
|
||||||
- `'networkidle0'` - consider setting content to be finished when there are no more than 0 network connections for at least `500` ms.
|
- `'networkidle'` - consider setting content to be finished when there are no network connections for at least `500` ms.
|
||||||
- `'networkidle2'` - consider setting content to be finished when there are no more than 2 network connections for at least `500` ms.
|
|
||||||
- returns: <[Promise]>
|
- returns: <[Promise]>
|
||||||
|
|
||||||
#### page.setDefaultNavigationTimeout(timeout)
|
#### page.setDefaultNavigationTimeout(timeout)
|
||||||
|
|
@ -1736,11 +1731,10 @@ await page.waitForFunction(selector => !!document.querySelector(selector), selec
|
||||||
Shortcut for [page.mainFrame().waitForFunction(pageFunction, arg, options]])](#framewaitforfunctionpagefunction-arg-options).
|
Shortcut for [page.mainFrame().waitForFunction(pageFunction, arg, options]])](#framewaitforfunctionpagefunction-arg-options).
|
||||||
|
|
||||||
#### page.waitForLoadState([state[, options]])
|
#### page.waitForLoadState([state[, options]])
|
||||||
- `state` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"> Load state to wait for, defaults to `load`. If the state has been already reached while loading current document, the method resolves immediately.
|
- `state` <"load"|"domcontentloaded"|"networkidle"> Load state to wait for, defaults to `load`. If the state has been already reached while loading current document, the method resolves immediately.
|
||||||
- `'load'` - wait for the `load` event to be fired.
|
- `'load'` - wait for the `load` event to be fired.
|
||||||
- `'domcontentloaded'` - wait for the `DOMContentLoaded` event to be fired.
|
- `'domcontentloaded'` - wait for the `DOMContentLoaded` event to be fired.
|
||||||
- `'networkidle0'` - wait until there are no more than 0 network connections for at least `500` ms.
|
- `'networkidle'` - wait until there are no network connections for at least `500` ms.
|
||||||
- `'networkidle2'` - wait until there are no more than 2 network connections for at least `500` ms.
|
|
||||||
- `options` <[Object]>
|
- `options` <[Object]>
|
||||||
- `timeout` <[number]> Maximum waiting time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultNavigationTimeout(timeout)](#browsercontextsetdefaultnavigationtimeouttimeout), [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout), [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
|
- `timeout` <[number]> Maximum waiting time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultNavigationTimeout(timeout)](#browsercontextsetdefaultnavigationtimeouttimeout), [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout), [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
|
||||||
- returns: <[Promise]> Promise which resolves when the required load state has been reached.
|
- returns: <[Promise]> Promise which resolves when the required load state has been reached.
|
||||||
|
|
@ -1767,11 +1761,10 @@ Shortcut for [page.mainFrame().waitForLoadState([options])](#framewaitforloadsta
|
||||||
- `options` <[Object]> Navigation parameters which might have the following properties:
|
- `options` <[Object]> Navigation parameters which might have the following properties:
|
||||||
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultNavigationTimeout(timeout)](#browsercontextsetdefaultnavigationtimeouttimeout), [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout), [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
|
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultNavigationTimeout(timeout)](#browsercontextsetdefaultnavigationtimeouttimeout), [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout), [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
|
||||||
- `url` <[string]|[RegExp]|[Function]> A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation.
|
- `url` <[string]|[RegExp]|[Function]> A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation.
|
||||||
- `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"> When to consider navigation succeeded, defaults to `load`. Events can be either:
|
- `waitUntil` <"load"|"domcontentloaded"|"networkidle"> When to consider navigation succeeded, defaults to `load`. Events can be either:
|
||||||
- `'domcontentloaded'` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
|
- `'domcontentloaded'` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
|
||||||
- `'load'` - consider navigation to be finished when the `load` event is fired.
|
- `'load'` - consider navigation to be finished when the `load` event is fired.
|
||||||
- `'networkidle0'` - consider navigation to be finished when there are no more than 0 network connections for at least `500` ms.
|
- `'networkidle'` - consider navigation to be finished when there are no network connections for at least `500` ms.
|
||||||
- `'networkidle2'` - consider navigation to be finished when there are no more than 2 network connections for at least `500` ms.
|
|
||||||
- returns: <[Promise]<?[Response]>> Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect. In case of navigation to a different anchor or navigation due to History API usage, the navigation will resolve with `null`.
|
- returns: <[Promise]<?[Response]>> Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect. In case of navigation to a different anchor or navigation due to History API usage, the navigation will resolve with `null`.
|
||||||
|
|
||||||
This resolves when the page navigates to a new URL or reloads. It is useful for when you run code
|
This resolves when the page navigates to a new URL or reloads. It is useful for when you run code
|
||||||
|
|
@ -2154,11 +2147,10 @@ console.log(frame === contentFrame); // -> true
|
||||||
- `url` <[string]> URL to navigate frame to. The url should include scheme, e.g. `https://`.
|
- `url` <[string]> URL to navigate frame to. The url should include scheme, e.g. `https://`.
|
||||||
- `options` <[Object]> Navigation parameters which might have the following properties:
|
- `options` <[Object]> Navigation parameters which might have the following properties:
|
||||||
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultNavigationTimeout(timeout)](#browsercontextsetdefaultnavigationtimeouttimeout), [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout), [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
|
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultNavigationTimeout(timeout)](#browsercontextsetdefaultnavigationtimeouttimeout), [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout), [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
|
||||||
- `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"> When to consider navigation succeeded, defaults to `load`. Events can be either:
|
- `waitUntil` <"load"|"domcontentloaded"|"networkidle"> When to consider navigation succeeded, defaults to `load`. Events can be either:
|
||||||
- `'domcontentloaded'` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
|
- `'domcontentloaded'` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
|
||||||
- `'load'` - consider navigation to be finished when the `load` event is fired.
|
- `'load'` - consider navigation to be finished when the `load` event is fired.
|
||||||
- `'networkidle0'` - consider navigation to be finished when there are no more than 0 network connections for at least `500` ms.
|
- `'networkidle'` - consider navigation to be finished when there are no network connections for at least `500` ms.
|
||||||
- `'networkidle2'` - consider navigation to be finished when there are no more than 2 network connections for at least `500` ms.
|
|
||||||
- `referer` <[string]> Referer header value. If provided it will take preference over the referer header value set by [page.setExtraHTTPHeaders()](#pagesetextrahttpheadersheaders).
|
- `referer` <[string]> Referer header value. If provided it will take preference over the referer header value set by [page.setExtraHTTPHeaders()](#pagesetextrahttpheadersheaders).
|
||||||
- returns: <[Promise]<?[Response]>> Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect.
|
- returns: <[Promise]<?[Response]>> Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect.
|
||||||
|
|
||||||
|
|
@ -2261,11 +2253,10 @@ frame.selectOption('select#colors', 'red', 'green', 'blue');
|
||||||
- `html` <[string]> HTML markup to assign to the page.
|
- `html` <[string]> HTML markup to assign to the page.
|
||||||
- `options` <[Object]> Parameters which might have the following properties:
|
- `options` <[Object]> Parameters which might have the following properties:
|
||||||
- `timeout` <[number]> Maximum time in milliseconds for resources to load, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultNavigationTimeout(timeout)](#browsercontextsetdefaultnavigationtimeouttimeout), [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout), [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
|
- `timeout` <[number]> Maximum time in milliseconds for resources to load, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultNavigationTimeout(timeout)](#browsercontextsetdefaultnavigationtimeouttimeout), [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout), [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
|
||||||
- `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"> When to consider navigation succeeded, defaults to `load`. Events can be either:
|
- `waitUntil` <"load"|"domcontentloaded"|"networkidle"> When to consider navigation succeeded, defaults to `load`. Events can be either:
|
||||||
- `'domcontentloaded'` - consider setting content to be finished when the `DOMContentLoaded` event is fired.
|
- `'domcontentloaded'` - consider setting content to be finished when the `DOMContentLoaded` event is fired.
|
||||||
- `'load'` - consider setting content to be finished when the `load` event is fired.
|
- `'load'` - consider setting content to be finished when the `load` event is fired.
|
||||||
- `'networkidle0'` - consider setting content to be finished when there are no more than 0 network connections for at least `500` ms.
|
- `'networkidle'` - consider setting content to be finished when there are no network connections for at least `500` ms.
|
||||||
- `'networkidle2'` - consider setting content to be finished when there are no more than 2 network connections for at least `500` ms.
|
|
||||||
- returns: <[Promise]>
|
- returns: <[Promise]>
|
||||||
|
|
||||||
#### frame.setInputFiles(selector, files[, options])
|
#### frame.setInputFiles(selector, files[, options])
|
||||||
|
|
@ -2389,11 +2380,10 @@ await frame.waitForFunction(selector => !!document.querySelector(selector), sele
|
||||||
```
|
```
|
||||||
|
|
||||||
#### frame.waitForLoadState([state[, options]])
|
#### frame.waitForLoadState([state[, options]])
|
||||||
- `state` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"> Load state to wait for, defaults to `load`. If the state has been already reached while loading current document, the method resolves immediately.
|
- `state` <"load"|"domcontentloaded"|"networkidle"> Load state to wait for, defaults to `load`. If the state has been already reached while loading current document, the method resolves immediately.
|
||||||
- `'load'` - wait for the `load` event to be fired.
|
- `'load'` - wait for the `load` event to be fired.
|
||||||
- `'domcontentloaded'` - wait for the `DOMContentLoaded` event to be fired.
|
- `'domcontentloaded'` - wait for the `DOMContentLoaded` event to be fired.
|
||||||
- `'networkidle0'` - wait until there are no more than 0 network connections for at least `500` ms.
|
- `'networkidle'` - wait until there are no network connections for at least `500` ms.
|
||||||
- `'networkidle2'` - wait until there are no more than 2 network connections for at least `500` ms.
|
|
||||||
- `options` <[Object]>
|
- `options` <[Object]>
|
||||||
- `timeout` <[number]> Maximum waiting time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultNavigationTimeout(timeout)](#browsercontextsetdefaultnavigationtimeouttimeout), [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout), [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
|
- `timeout` <[number]> Maximum waiting time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultNavigationTimeout(timeout)](#browsercontextsetdefaultnavigationtimeouttimeout), [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout), [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
|
||||||
- returns: <[Promise]> Promise which resolves when the required load state has been reached.
|
- returns: <[Promise]> Promise which resolves when the required load state has been reached.
|
||||||
|
|
@ -2409,11 +2399,10 @@ await frame.waitForLoadState(); // The promise resolves after 'load' event.
|
||||||
- `options` <[Object]> Navigation parameters which might have the following properties:
|
- `options` <[Object]> Navigation parameters which might have the following properties:
|
||||||
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultNavigationTimeout(timeout)](#browsercontextsetdefaultnavigationtimeouttimeout), [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout), [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
|
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultNavigationTimeout(timeout)](#browsercontextsetdefaultnavigationtimeouttimeout), [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout), [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
|
||||||
- `url` <[string]|[RegExp]|[Function]> URL string, URL regex pattern or predicate receiving [URL] to match while waiting for the navigation.
|
- `url` <[string]|[RegExp]|[Function]> URL string, URL regex pattern or predicate receiving [URL] to match while waiting for the navigation.
|
||||||
- `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"> When to consider navigation succeeded, defaults to `load`. Events can be either:
|
- `waitUntil` <"load"|"domcontentloaded"|"networkidle"> When to consider navigation succeeded, defaults to `load`. Events can be either:
|
||||||
- `'domcontentloaded'` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
|
- `'domcontentloaded'` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
|
||||||
- `'load'` - consider navigation to be finished when the `load` event is fired.
|
- `'load'` - consider navigation to be finished when the `load` event is fired.
|
||||||
- `'networkidle0'` - consider navigation to be finished when there are no more than 0 network connections for at least `500` ms.
|
- `'networkidle'` - consider navigation to be finished when there are no network connections for at least `500` ms.
|
||||||
- `'networkidle2'` - consider navigation to be finished when there are no more than 2 network connections for at least `500` ms.
|
|
||||||
- returns: <[Promise]<?[Response]>> Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect. In case of navigation to a different anchor or navigation due to History API usage, the navigation will resolve with `null`.
|
- returns: <[Promise]<?[Response]>> Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect. In case of navigation to a different anchor or navigation due to History API usage, the navigation will resolve with `null`.
|
||||||
|
|
||||||
This resolves when the frame navigates to a new URL. It is useful for when you run code
|
This resolves when the frame navigates to a new URL. It is useful for when you run code
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
# Continuous integration.md
|
# Continuous integration
|
||||||
|
|
||||||
Playwright tests can be executed to run on your CI environments. To simplify this, we have created sample configurations for common CI providers that can be used to bootstrap your setup.
|
Playwright tests can be executed to run on your CI environments. To simplify this, we have created sample configurations for common CI providers that can be used to bootstrap your setup.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -168,16 +168,7 @@ await page.click('css:light=div');
|
||||||
Selectors using the same or different engines can be combined using the `>>` separator. For example,
|
Selectors using the same or different engines can be combined using the `>>` separator. For example,
|
||||||
|
|
||||||
```js
|
```js
|
||||||
await page.click('css=article >> css=.bar > .baz >> css=span[attr=value]');
|
await page.click('#free-month-promo >> text=Learn more');
|
||||||
```
|
|
||||||
|
|
||||||
is equivalent to
|
|
||||||
|
|
||||||
```js
|
|
||||||
document
|
|
||||||
.querySelector('article')
|
|
||||||
.querySelector('.bar > .baz')
|
|
||||||
.querySelector('span[attr=value]')
|
|
||||||
```
|
```
|
||||||
|
|
||||||
<br/>
|
<br/>
|
||||||
|
|
|
||||||
51
docs/extensibility.md
Normal file
51
docs/extensibility.md
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
# Extensibility
|
||||||
|
|
||||||
|
#### Contents
|
||||||
|
|
||||||
|
- [Custom selector engines](#custom-selector-engines)
|
||||||
|
|
||||||
|
## Custom selector engines
|
||||||
|
|
||||||
|
Playwright supports custom selector engines, registered with [selectors.register(name, script[, options])](api.md#selectorsregistername-script-options).
|
||||||
|
|
||||||
|
Selector engine should have the following properties:
|
||||||
|
|
||||||
|
- `create` function to create a relative selector from `root` (root is either a `Document`, `ShadowRoot` or `Element`) to a `target` element.
|
||||||
|
- `query` function to query first element matching `selector` relative to the `root`.
|
||||||
|
- `queryAll` function to query all elements matching `selector` relative to the `root`.
|
||||||
|
|
||||||
|
By default the engine is run directly in the frame's JavaScript context and, for example, can call an application-defined function. To isolate the engine from any JavaScript in the frame, but leave access to the DOM, resgister the engine with `{contentScript: true}` option. Content script engine is safer because it is protected from any tampering with the global objects, for example altering `Node.prototype` methods. All built-in selector engines run as content scripts. Note that running as a content script is not guaranteed when the engine is used together with other custom engines.
|
||||||
|
|
||||||
|
An example of registering selector engine that queries elements based on a tag name:
|
||||||
|
```js
|
||||||
|
// Must be a function that evaluates to a selector engine instance.
|
||||||
|
const createTagNameEngine = () => ({
|
||||||
|
// Creates a selector that matches given target when queried at the root.
|
||||||
|
// Can return undefined if unable to create one.
|
||||||
|
create(root, target) {
|
||||||
|
return root.querySelector(target.tagName) === target ? target.tagName : undefined;
|
||||||
|
},
|
||||||
|
|
||||||
|
// Returns the first element matching given selector in the root's subtree.
|
||||||
|
query(root, selector) {
|
||||||
|
return root.querySelector(selector);
|
||||||
|
},
|
||||||
|
|
||||||
|
// Returns all elements matching given selector in the root's subtree.
|
||||||
|
queryAll(root, selector) {
|
||||||
|
return Array.from(root.querySelectorAll(selector));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Register the engine. Selectors will be prefixed with "tag=".
|
||||||
|
await selectors.register('tag', createTagNameEngine);
|
||||||
|
|
||||||
|
// Now we can use 'tag=' selectors.
|
||||||
|
const button = await page.$('tag=button');
|
||||||
|
|
||||||
|
// We can combine it with other selector engines using `>>` combinator.
|
||||||
|
await page.click('tag=div >> span >> "Click me"');
|
||||||
|
|
||||||
|
// We can use it in any methods supporting selectors.
|
||||||
|
const buttonCount = await page.$$eval('tag=button', buttons => buttons.length);
|
||||||
|
```
|
||||||
|
|
@ -38,7 +38,7 @@ Page load takes time retrieving the response body over the network, parsing, exe
|
||||||
- page executes some scripts and loads resources like stylesheets and images
|
- page executes some scripts and loads resources like stylesheets and images
|
||||||
- [`load`](api.md#event-load) event is fired
|
- [`load`](api.md#event-load) event is fired
|
||||||
- page executes dynamically loaded scripts
|
- page executes dynamically loaded scripts
|
||||||
- `networkidle0` is fired - no new network requests made for at least `500` ms
|
- `networkidle` is fired - no new network requests made for at least `500` ms
|
||||||
|
|
||||||
### Common scenarios
|
### Common scenarios
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -206,12 +206,9 @@ export class FrameManager {
|
||||||
frame._firedLifecycleEvents.clear();
|
frame._firedLifecycleEvents.clear();
|
||||||
// Keep the current navigation request if any.
|
// Keep the current navigation request if any.
|
||||||
frame._inflightRequests = new Set(Array.from(frame._inflightRequests).filter(request => request._documentId === frame._lastDocumentId));
|
frame._inflightRequests = new Set(Array.from(frame._inflightRequests).filter(request => request._documentId === frame._lastDocumentId));
|
||||||
this._stopNetworkIdleTimer(frame, 'networkidle0');
|
frame._stopNetworkIdleTimer();
|
||||||
if (frame._inflightRequests.size === 0)
|
if (frame._inflightRequests.size === 0)
|
||||||
this._startNetworkIdleTimer(frame, 'networkidle0');
|
frame._startNetworkIdleTimer();
|
||||||
this._stopNetworkIdleTimer(frame, 'networkidle2');
|
|
||||||
if (frame._inflightRequests.size <= 2)
|
|
||||||
this._startNetworkIdleTimer(frame, 'networkidle2');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
requestStarted(request: network.Request) {
|
requestStarted(request: network.Request) {
|
||||||
|
|
@ -282,9 +279,7 @@ export class FrameManager {
|
||||||
return;
|
return;
|
||||||
frame._inflightRequests.delete(request);
|
frame._inflightRequests.delete(request);
|
||||||
if (frame._inflightRequests.size === 0)
|
if (frame._inflightRequests.size === 0)
|
||||||
this._startNetworkIdleTimer(frame, 'networkidle0');
|
frame._startNetworkIdleTimer();
|
||||||
if (frame._inflightRequests.size === 2)
|
|
||||||
this._startNetworkIdleTimer(frame, 'networkidle2');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _inflightRequestStarted(request: network.Request) {
|
private _inflightRequestStarted(request: network.Request) {
|
||||||
|
|
@ -293,25 +288,7 @@ export class FrameManager {
|
||||||
return;
|
return;
|
||||||
frame._inflightRequests.add(request);
|
frame._inflightRequests.add(request);
|
||||||
if (frame._inflightRequests.size === 1)
|
if (frame._inflightRequests.size === 1)
|
||||||
this._stopNetworkIdleTimer(frame, 'networkidle0');
|
frame._stopNetworkIdleTimer();
|
||||||
if (frame._inflightRequests.size === 3)
|
|
||||||
this._stopNetworkIdleTimer(frame, 'networkidle2');
|
|
||||||
}
|
|
||||||
|
|
||||||
private _startNetworkIdleTimer(frame: Frame, event: types.LifecycleEvent) {
|
|
||||||
assert(!frame._networkIdleTimers.has(event));
|
|
||||||
if (frame._firedLifecycleEvents.has(event))
|
|
||||||
return;
|
|
||||||
frame._networkIdleTimers.set(event, setTimeout(() => {
|
|
||||||
this.frameLifecycleEvent(frame._id, event);
|
|
||||||
}, 500));
|
|
||||||
}
|
|
||||||
|
|
||||||
private _stopNetworkIdleTimer(frame: Frame, event: types.LifecycleEvent) {
|
|
||||||
const timeoutId = frame._networkIdleTimers.get(event);
|
|
||||||
if (timeoutId)
|
|
||||||
clearTimeout(timeoutId);
|
|
||||||
frame._networkIdleTimers.delete(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interceptConsoleMessage(message: ConsoleMessage): boolean {
|
interceptConsoleMessage(message: ConsoleMessage): boolean {
|
||||||
|
|
@ -341,7 +318,7 @@ export class Frame {
|
||||||
private _childFrames = new Set<Frame>();
|
private _childFrames = new Set<Frame>();
|
||||||
_name = '';
|
_name = '';
|
||||||
_inflightRequests = new Set<network.Request>();
|
_inflightRequests = new Set<network.Request>();
|
||||||
readonly _networkIdleTimers = new Map<types.LifecycleEvent, NodeJS.Timer>();
|
private _networkIdleTimer: NodeJS.Timer | undefined;
|
||||||
private _setContentCounter = 0;
|
private _setContentCounter = 0;
|
||||||
readonly _detachedPromise: Promise<void>;
|
readonly _detachedPromise: Promise<void>;
|
||||||
private _detachedCallback = () => {};
|
private _detachedCallback = () => {};
|
||||||
|
|
@ -859,6 +836,19 @@ export class Frame {
|
||||||
this._setContext(contextType, null);
|
this._setContext(contextType, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_startNetworkIdleTimer() {
|
||||||
|
assert(!this._networkIdleTimer);
|
||||||
|
if (this._firedLifecycleEvents.has('networkidle'))
|
||||||
|
return;
|
||||||
|
this._networkIdleTimer = setTimeout(() => { this._page._frameManager.frameLifecycleEvent(this._id, 'networkidle'); }, 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
_stopNetworkIdleTimer() {
|
||||||
|
if (this._networkIdleTimer)
|
||||||
|
clearTimeout(this._networkIdleTimer);
|
||||||
|
this._networkIdleTimer = undefined;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Task = (context: dom.FrameExecutionContext) => Promise<js.JSHandle>;
|
type Task = (context: dom.FrameExecutionContext) => Promise<js.JSHandle>;
|
||||||
|
|
|
||||||
|
|
@ -42,8 +42,8 @@ export type WaitForElementOptions = TimeoutOptions & { waitFor?: 'attached' | 'd
|
||||||
export type Polling = 'raf' | 'mutation' | number;
|
export type Polling = 'raf' | 'mutation' | number;
|
||||||
export type WaitForFunctionOptions = TimeoutOptions & { polling?: Polling };
|
export type WaitForFunctionOptions = TimeoutOptions & { polling?: Polling };
|
||||||
|
|
||||||
export type LifecycleEvent = 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2';
|
export type LifecycleEvent = 'load' | 'domcontentloaded' | 'networkidle';
|
||||||
export const kLifecycleEvents: Set<LifecycleEvent> = new Set(['load', 'domcontentloaded', 'networkidle0', 'networkidle2']);
|
export const kLifecycleEvents: Set<LifecycleEvent> = new Set(['load', 'domcontentloaded', 'networkidle']);
|
||||||
|
|
||||||
export type NavigateOptions = TimeoutOptions & {
|
export type NavigateOptions = TimeoutOptions & {
|
||||||
waitUntil?: LifecycleEvent,
|
waitUntil?: LifecycleEvent,
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,11 @@ async function sleep(delay) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
|
window.ws = new WebSocket('ws://localhost:' + window.location.port + '/ws');
|
||||||
|
window.ws.addEventListener('message', message => {});
|
||||||
|
|
||||||
const roundOne = Promise.all([
|
const roundOne = Promise.all([
|
||||||
fetch('fetch-request-a.js'),
|
fetch('fetch-request-a.js'),
|
||||||
fetch('fetch-request-b.js'),
|
|
||||||
fetch('fetch-request-c.js'),
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
await roundOne;
|
await roundOne;
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ describe('Auto waiting', () => {
|
||||||
]);
|
]);
|
||||||
expect(messages.join('|')).toBe('popup|click');
|
expect(messages.join('|')).toBe('popup|click');
|
||||||
});
|
});
|
||||||
it('should await download when clicking anchor', async function({page, server}) {
|
it.fail(CHROMIUM)('should await download when clicking anchor', async function({page, server}) {
|
||||||
server.setRoute('/download', (req, res) => {
|
server.setRoute('/download', (req, res) => {
|
||||||
res.setHeader('Content-Type', 'application/octet-stream');
|
res.setHeader('Content-Type', 'application/octet-stream');
|
||||||
res.setHeader('Content-Disposition', 'attachment');
|
res.setHeader('Content-Disposition', 'attachment');
|
||||||
|
|
|
||||||
|
|
@ -172,9 +172,14 @@ describe('Page.goto', function() {
|
||||||
await page.goto(server.CROSS_PROCESS_PREFIX + '/empty.html');
|
await page.goto(server.CROSS_PROCESS_PREFIX + '/empty.html');
|
||||||
await page.goto(httpsServer.EMPTY_PAGE).catch(e => void 0);
|
await page.goto(httpsServer.EMPTY_PAGE).catch(e => void 0);
|
||||||
});
|
});
|
||||||
it('should throw if networkidle is passed as an option', async({page, server}) => {
|
it('should throw if networkidle0 is passed as an option', async({page, server}) => {
|
||||||
let error = null;
|
let error = null;
|
||||||
await page.goto(server.EMPTY_PAGE, {waitUntil: 'networkidle'}).catch(err => error = err);
|
await page.goto(server.EMPTY_PAGE, {waitUntil: 'networkidle0'}).catch(err => error = err);
|
||||||
|
expect(error.message).toContain('Unsupported waitUntil option');
|
||||||
|
});
|
||||||
|
it('should throw if networkidle2 is passed as an option', async({page, server}) => {
|
||||||
|
let error = null;
|
||||||
|
await page.goto(server.EMPTY_PAGE, {waitUntil: 'networkidle2'}).catch(err => error = err);
|
||||||
expect(error.message).toContain('Unsupported waitUntil option');
|
expect(error.message).toContain('Unsupported waitUntil option');
|
||||||
});
|
});
|
||||||
it('should fail when main resources failed to load', async({page, server}) => {
|
it('should fail when main resources failed to load', async({page, server}) => {
|
||||||
|
|
@ -407,23 +412,18 @@ describe('Page.goto', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('network idle', function() {
|
describe('network idle', function() {
|
||||||
it('should navigate to empty page with networkidle0', async({page, server}) => {
|
it('should navigate to empty page with networkidle', async({page, server}) => {
|
||||||
const response = await page.goto(server.EMPTY_PAGE, { waitUntil: 'networkidle0' });
|
const response = await page.goto(server.EMPTY_PAGE, { waitUntil: 'networkidle' });
|
||||||
expect(response.status()).toBe(200);
|
|
||||||
});
|
|
||||||
it('should navigate to empty page with networkidle2', async({page, server}) => {
|
|
||||||
const response = await page.goto(server.EMPTY_PAGE, { waitUntil: 'networkidle2' });
|
|
||||||
expect(response.status()).toBe(200);
|
expect(response.status()).toBe(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {import('../src/frames').Frame} frame
|
* @param {import('../src/frames').Frame} frame
|
||||||
* @param {TestServer} server
|
* @param {TestServer} server
|
||||||
* @param {'networkidle0'|'networkidle2'} signal
|
|
||||||
* @param {() => Promise<void>} action
|
* @param {() => Promise<void>} action
|
||||||
* @param {boolean} isSetContent
|
* @param {boolean} isSetContent
|
||||||
*/
|
*/
|
||||||
async function networkIdleTest(frame, server, signal, action, isSetContent) {
|
async function networkIdleTest(frame, server, action, isSetContent) {
|
||||||
const finishResponse = response => {
|
const finishResponse = response => {
|
||||||
response.statusCode = 404;
|
response.statusCode = 404;
|
||||||
response.end(`File not found`);
|
response.end(`File not found`);
|
||||||
|
|
@ -437,19 +437,13 @@ describe('Page.goto', function() {
|
||||||
let responses = {};
|
let responses = {};
|
||||||
// Hold on to a bunch of requests without answering.
|
// Hold on to a bunch of requests without answering.
|
||||||
server.setRoute('/fetch-request-a.js', (req, res) => responses.a = res);
|
server.setRoute('/fetch-request-a.js', (req, res) => responses.a = res);
|
||||||
server.setRoute('/fetch-request-b.js', (req, res) => responses.b = res);
|
|
||||||
server.setRoute('/fetch-request-c.js', (req, res) => responses.c = res);
|
|
||||||
const initialFetchResourcesRequested = Promise.all([
|
const initialFetchResourcesRequested = Promise.all([
|
||||||
waitForRequest('/fetch-request-a.js'),
|
waitForRequest('/fetch-request-a.js'),
|
||||||
waitForRequest('/fetch-request-b.js'),
|
|
||||||
waitForRequest('/fetch-request-c.js')
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
let secondFetchResourceRequested;
|
let secondFetchResourceRequested;
|
||||||
if (signal === 'networkidle0') {
|
server.setRoute('/fetch-request-d.js', (req, res) => responses.d = res);
|
||||||
server.setRoute('/fetch-request-d.js', (req, res) => responses.d = res);
|
secondFetchResourceRequested = waitForRequest('/fetch-request-d.js');
|
||||||
secondFetchResourceRequested = waitForRequest('/fetch-request-d.js');
|
|
||||||
}
|
|
||||||
|
|
||||||
const waitForLoadPromise = isSetContent ? Promise.resolve() : frame.waitForNavigation({ waitUntil: 'load' });
|
const waitForLoadPromise = isSetContent ? Promise.resolve() : frame.waitForNavigation({ waitUntil: 'load' });
|
||||||
|
|
||||||
|
|
@ -470,139 +464,73 @@ describe('Page.goto', function() {
|
||||||
expect(actionFinished).toBe(false);
|
expect(actionFinished).toBe(false);
|
||||||
|
|
||||||
expect(responses.a).toBeTruthy();
|
expect(responses.a).toBeTruthy();
|
||||||
expect(responses.b).toBeTruthy();
|
|
||||||
expect(responses.c).toBeTruthy();
|
|
||||||
let timer;
|
let timer;
|
||||||
let timerTriggered = false;
|
let timerTriggered = false;
|
||||||
if (signal === 'networkidle0') {
|
// Finishing response should trigger the second round.
|
||||||
// Finishing first response should leave 2 requests alive and trigger networkidle2.
|
finishResponse(responses.a);
|
||||||
finishResponse(responses.a);
|
|
||||||
// Finishing two more responses should trigger the second round.
|
// Wait for the second round to be requested.
|
||||||
finishResponse(responses.b);
|
await secondFetchResourceRequested;
|
||||||
finishResponse(responses.c);
|
expect(actionFinished).toBe(false);
|
||||||
|
// Finishing the last response should trigger networkidle.
|
||||||
|
timer = setTimeout(() => timerTriggered = true, 500);
|
||||||
|
finishResponse(responses.d);
|
||||||
|
|
||||||
// Wait for the second round to be requested.
|
|
||||||
await secondFetchResourceRequested;
|
|
||||||
expect(actionFinished).toBe(false);
|
|
||||||
// Finishing the last response should trigger networkidle0.
|
|
||||||
timer = setTimeout(() => timerTriggered = true, 500);
|
|
||||||
finishResponse(responses.d);
|
|
||||||
} else {
|
|
||||||
timer = setTimeout(() => timerTriggered = true, 500);
|
|
||||||
// Finishing first response should leave 2 requests alive and trigger networkidle2.
|
|
||||||
finishResponse(responses.a);
|
|
||||||
}
|
|
||||||
const response = await actionPromise;
|
const response = await actionPromise;
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
expect(timerTriggered).toBe(true);
|
expect(timerTriggered).toBe(true);
|
||||||
if (!isSetContent)
|
if (!isSetContent)
|
||||||
expect(response.ok()).toBe(true);
|
expect(response.ok()).toBe(true);
|
||||||
|
|
||||||
if (signal === 'networkidle2') {
|
|
||||||
// Cleanup.
|
|
||||||
finishResponse(responses.b);
|
|
||||||
finishResponse(responses.c);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
it('should wait for networkidle0 to succeed navigation', async({page, server}) => {
|
it('should wait for networkidle to succeed navigation', async({page, server}) => {
|
||||||
await networkIdleTest(page.mainFrame(), server, 'networkidle0', () => {
|
await networkIdleTest(page.mainFrame(), server, () => {
|
||||||
return page.goto(server.PREFIX + '/networkidle.html', { waitUntil: 'networkidle0' });
|
return page.goto(server.PREFIX + '/networkidle.html', { waitUntil: 'networkidle' });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('should wait for networkidle2 to succeed navigation', async({page, server}) => {
|
it('should wait for networkidle to succeed navigation with request from previous navigation', async({page, server}) => {
|
||||||
await networkIdleTest(page.mainFrame(), server, 'networkidle2', () => {
|
|
||||||
return page.goto(server.PREFIX + '/networkidle.html', { waitUntil: 'networkidle2' });
|
|
||||||
});
|
|
||||||
});
|
|
||||||
it('should wait for networkidle0 to succeed navigation with request from previous navigation', async({page, server}) => {
|
|
||||||
await page.goto(server.EMPTY_PAGE);
|
await page.goto(server.EMPTY_PAGE);
|
||||||
server.setRoute('/foo.js', () => {});
|
server.setRoute('/foo.js', () => {});
|
||||||
await page.setContent(`<script>fetch('foo.js');</script>`);
|
await page.setContent(`<script>fetch('foo.js');</script>`);
|
||||||
await networkIdleTest(page.mainFrame(), server, 'networkidle0', () => {
|
await networkIdleTest(page.mainFrame(), server, () => {
|
||||||
return page.goto(server.PREFIX + '/networkidle.html', { waitUntil: 'networkidle0' });
|
return page.goto(server.PREFIX + '/networkidle.html', { waitUntil: 'networkidle' });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('should wait for networkidle2 to succeed navigation with request from previous navigation', async({page, server}) => {
|
it('should wait for networkidle in waitForNavigation', async({page, server}) => {
|
||||||
await page.goto(server.EMPTY_PAGE);
|
await networkIdleTest(page.mainFrame(), server, () => {
|
||||||
server.setRoute('/foo.js', () => {});
|
const promise = page.waitForNavigation({ waitUntil: 'networkidle' });
|
||||||
await page.setContent(`<script>fetch('foo.js');</script>`);
|
|
||||||
await networkIdleTest(page.mainFrame(), server, 'networkidle2', () => {
|
|
||||||
return page.goto(server.PREFIX + '/networkidle.html', { waitUntil: 'networkidle2' });
|
|
||||||
});
|
|
||||||
});
|
|
||||||
it('should wait for networkidle0 in waitForNavigation', async({page, server}) => {
|
|
||||||
await networkIdleTest(page.mainFrame(), server, 'networkidle0', () => {
|
|
||||||
const promise = page.waitForNavigation({ waitUntil: 'networkidle0' });
|
|
||||||
page.goto(server.PREFIX + '/networkidle.html');
|
page.goto(server.PREFIX + '/networkidle.html');
|
||||||
return promise;
|
return promise;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('should wait for networkidle2 in waitForNavigation', async({page, server}) => {
|
it('should wait for networkidle in setContent', async({page, server}) => {
|
||||||
await networkIdleTest(page.mainFrame(), server, 'networkidle2', () => {
|
|
||||||
const promise = page.waitForNavigation({ waitUntil: 'networkidle2' });
|
|
||||||
page.goto(server.PREFIX + '/networkidle.html');
|
|
||||||
return promise;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
it('should wait for networkidle0 in setContent', async({page, server}) => {
|
|
||||||
await page.goto(server.EMPTY_PAGE);
|
await page.goto(server.EMPTY_PAGE);
|
||||||
await networkIdleTest(page.mainFrame(), server, 'networkidle0', () => {
|
await networkIdleTest(page.mainFrame(), server, () => {
|
||||||
return page.setContent(`<script src='networkidle.js'></script>`, { waitUntil: 'networkidle0' });
|
return page.setContent(`<script src='networkidle.js'></script>`, { waitUntil: 'networkidle' });
|
||||||
}, true);
|
}, true);
|
||||||
});
|
});
|
||||||
it('should wait for networkidle2 in setContent', async({page, server}) => {
|
it('should wait for networkidle in setContent with request from previous navigation', async({page, server}) => {
|
||||||
await page.goto(server.EMPTY_PAGE);
|
|
||||||
await networkIdleTest(page.mainFrame(), server, 'networkidle2', () => {
|
|
||||||
return page.setContent(`<script src='networkidle.js'></script>`, { waitUntil: 'networkidle2' });
|
|
||||||
}, true);
|
|
||||||
});
|
|
||||||
it('should wait for networkidle0 in setContent with request from previous navigation', async({page, server}) => {
|
|
||||||
await page.goto(server.EMPTY_PAGE);
|
await page.goto(server.EMPTY_PAGE);
|
||||||
server.setRoute('/foo.js', () => {});
|
server.setRoute('/foo.js', () => {});
|
||||||
await page.setContent(`<script>fetch('foo.js');</script>`);
|
await page.setContent(`<script>fetch('foo.js');</script>`);
|
||||||
await networkIdleTest(page.mainFrame(), server, 'networkidle0', () => {
|
await networkIdleTest(page.mainFrame(), server, () => {
|
||||||
return page.setContent(`<script src='networkidle.js'></script>`, { waitUntil: 'networkidle0' });
|
return page.setContent(`<script src='networkidle.js'></script>`, { waitUntil: 'networkidle' });
|
||||||
}, true);
|
}, true);
|
||||||
});
|
});
|
||||||
it('should wait for networkidle2 in setContent with request from previous navigation', async({page, server}) => {
|
it('should wait for networkidle when navigating iframe', async({page, server}) => {
|
||||||
await page.goto(server.EMPTY_PAGE);
|
|
||||||
server.setRoute('/foo.js', () => {});
|
|
||||||
await page.setContent(`<script>fetch('foo.js');</script>`);
|
|
||||||
await networkIdleTest(page.mainFrame(), server, 'networkidle2', () => {
|
|
||||||
return page.setContent(`<script src='networkidle.js'></script>`, { waitUntil: 'networkidle2' });
|
|
||||||
}, true);
|
|
||||||
});
|
|
||||||
it('should wait for networkidle0 when navigating iframe', async({page, server}) => {
|
|
||||||
await page.goto(server.PREFIX + '/frames/one-frame.html');
|
await page.goto(server.PREFIX + '/frames/one-frame.html');
|
||||||
const frame = page.mainFrame().childFrames()[0];
|
const frame = page.mainFrame().childFrames()[0];
|
||||||
await networkIdleTest(frame, server, 'networkidle0', () => frame.goto(server.PREFIX + '/networkidle.html', { waitUntil: 'networkidle0' }));
|
await networkIdleTest(frame, server, () => frame.goto(server.PREFIX + '/networkidle.html', { waitUntil: 'networkidle' }));
|
||||||
});
|
});
|
||||||
it('should wait for networkidle2 when navigating iframe', async({page, server}) => {
|
it('should wait for networkidle in setContent from the child frame', async({page, server}) => {
|
||||||
await page.goto(server.PREFIX + '/frames/one-frame.html');
|
|
||||||
const frame = page.mainFrame().childFrames()[0];
|
|
||||||
await networkIdleTest(frame, server, 'networkidle2', () => frame.goto(server.PREFIX + '/networkidle.html', { waitUntil: 'networkidle2' }));
|
|
||||||
});
|
|
||||||
it('should wait for networkidle0 in setContent from the child frame', async({page, server}) => {
|
|
||||||
await page.goto(server.EMPTY_PAGE);
|
await page.goto(server.EMPTY_PAGE);
|
||||||
await networkIdleTest(page.mainFrame(), server, 'networkidle0', () => {
|
await networkIdleTest(page.mainFrame(), server, () => {
|
||||||
return page.setContent(`<iframe src='networkidle.html'></iframe>`, { waitUntil: 'networkidle0' });
|
return page.setContent(`<iframe src='networkidle.html'></iframe>`, { waitUntil: 'networkidle' });
|
||||||
}, true);
|
}, true);
|
||||||
});
|
});
|
||||||
it('should wait for networkidle2 in setContent from the child frame', async({page, server}) => {
|
it('should wait for networkidle from the child frame', async({page, server}) => {
|
||||||
await page.goto(server.EMPTY_PAGE);
|
await networkIdleTest(page.mainFrame(), server, () => {
|
||||||
await networkIdleTest(page.mainFrame(), server, 'networkidle2', () => {
|
return page.goto(server.PREFIX + '/networkidle-frame.html', { waitUntil: 'networkidle' });
|
||||||
return page.setContent(`<iframe src='networkidle.html'></iframe>`, { waitUntil: 'networkidle2' });
|
|
||||||
}, true);
|
|
||||||
});
|
|
||||||
it('should wait for networkidle0 from the child frame', async({page, server}) => {
|
|
||||||
await networkIdleTest(page.mainFrame(), server, 'networkidle0', () => {
|
|
||||||
return page.goto(server.PREFIX + '/networkidle-frame.html', { waitUntil: 'networkidle0' });
|
|
||||||
});
|
|
||||||
});
|
|
||||||
it('should wait for networkidle2 from the child frame', async({page, server}) => {
|
|
||||||
await networkIdleTest(page.mainFrame(), server, 'networkidle2', () => {
|
|
||||||
return page.goto(server.PREFIX + '/networkidle-frame.html', { waitUntil: 'networkidle2' });
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ type AssertNotAny<S> = {notRealProperty: number} extends S ? false : true;
|
||||||
(async () => {
|
(async () => {
|
||||||
const browser = await playwright.chromium.launch();
|
const browser = await playwright.chromium.launch();
|
||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
await page.goto('https://news.ycombinator.com', { waitUntil: 'networkidle0' });
|
await page.goto('https://news.ycombinator.com', { waitUntil: 'networkidle' });
|
||||||
await page.pdf({ path: 'hn.pdf', format: 'A4' });
|
await page.pdf({ path: 'hn.pdf', format: 'A4' });
|
||||||
|
|
||||||
browser.close();
|
browser.close();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue