feat(Page.goto): add a 'domcontentloaded' option to the Page.goto (#1145)
This patch adds a new `domcontentloaded` option to a bunch of navigation methods: - Page.goto - Page.waitForNavigation - Page.goBack - Page.goForward - Page.reload Fixes #946.
This commit is contained in:
parent
ce8a952044
commit
ef369e5d5d
@ -763,6 +763,7 @@ If there's no element matching `selector`, the method throws an error.
|
||||
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout.
|
||||
- `waitUntil` <[string]> When to consider a navigation finished, defaults to `load`. Can be either:
|
||||
- `load` - consider navigation to be finished when the `load` event is fired.
|
||||
- `domcontentloaded` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
|
||||
- `networkidle0` - consider navigation to be finished when there are no more then 0 network connections for at least `500` ms.
|
||||
- `networkidle2` - consider navigation to be finished when there are no more then 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
|
||||
@ -775,6 +776,7 @@ Navigate to the previous page in history.
|
||||
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout.
|
||||
- `waitUntil` <[string]> When to consider navigation succeeded, defaults to `load`. Can be either:
|
||||
- `load` - consider navigation to be finished when the `load` event is fired.
|
||||
- `domcontentloaded` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
|
||||
- `networkidle0` - consider navigation to be finished when there are no more then 0 network connections for at least `500` ms.
|
||||
- `networkidle2` - consider navigation to be finished when there are no more then 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
|
||||
@ -788,6 +790,7 @@ Navigate to the next page in history.
|
||||
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout.
|
||||
- `waitUntil` <[string]> When to consider navigation succeeded, defaults to `load`. Can be either:
|
||||
- `load` - consider navigation to be finished when the `load` event is fired.
|
||||
- `domcontentloaded` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
|
||||
- `networkidle0` - consider navigation to be finished when there are no more then 0 network connections for at least `500` ms.
|
||||
- `networkidle2` - consider navigation to be finished when there are no more then 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.
|
||||
@ -902,6 +905,7 @@ Shortcut for [page.mainFrame().executionContext().queryObjects(prototypeHandle)]
|
||||
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout.
|
||||
- `waitUntil` <[string]> When to consider navigation succeeded, defaults to `load`. Can be either:
|
||||
- `load` - consider navigation to be finished when the `load` event is fired.
|
||||
- `domcontentloaded` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
|
||||
- `networkidle0` - consider navigation to be finished when there are no more then 0 network connections for at least `500` ms.
|
||||
- `networkidle2` - consider navigation to be finished when there are no more then 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.
|
||||
@ -1105,6 +1109,7 @@ Shortcut for [page.mainFrame().waitForFunction(pageFunction[, options[, ...args]
|
||||
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout.
|
||||
- `waitUntil` <[string]> When to consider navigation succeeded, defaults to `load`. Can be either:
|
||||
- `load` - consider navigation to be finished when the `load` event is fired.
|
||||
- `domcontentloaded` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
|
||||
- `networkidle0` - consider navigation to be finished when there are no more then 0 network connections for at least `500` ms.
|
||||
- `networkidle2` - consider navigation to be finished when there are no more then 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.
|
||||
@ -2017,4 +2022,4 @@ Identifies what kind of target this is. Can be `"page"`, `"service_worker"`, or
|
||||
[Serializable]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable"
|
||||
[Touchscreen]: #class-touchscreen "Touchscreen"
|
||||
[Target]: #class-target "Target"
|
||||
[USKeyboardLayout]: ../lib/USKeyboardLayout.js "USKeyboardLayout"
|
||||
[USKeyboardLayout]: ../lib/USKeyboardLayout.js "USKeyboardLayout"
|
||||
|
@ -32,7 +32,7 @@ class NavigatorWatcher {
|
||||
this._ignoreHTTPSErrors = ignoreHTTPSErrors;
|
||||
this._timeout = typeof options['timeout'] === 'number' ? options['timeout'] : 30000;
|
||||
const waitUntil = typeof options['waitUntil'] === 'string' ? options['waitUntil'] : 'load';
|
||||
const isAllowedWaitUntil = waitUntil === 'networkidle0' || waitUntil === 'networkidle2' || waitUntil === 'load';
|
||||
const isAllowedWaitUntil = waitUntil === 'networkidle0' || waitUntil === 'networkidle2' || waitUntil === 'load' || waitUntil === 'domcontentloaded';
|
||||
console.assert(isAllowedWaitUntil, 'Unknown value for options.waitUntil: ' + waitUntil);
|
||||
this._pendingEvents = new Set([waitUntil]);
|
||||
}
|
||||
@ -92,8 +92,9 @@ class NavigatorWatcher {
|
||||
|
||||
const protocolLifecycleToPuppeteer = {
|
||||
'load': 'load',
|
||||
'DOMContentLoaded': 'domcontentloaded',
|
||||
'networkIdle': 'networkidle0',
|
||||
'networkAlmostIdle': 'networkidle2'
|
||||
'networkAlmostIdle': 'networkidle2',
|
||||
};
|
||||
|
||||
module.exports = NavigatorWatcher;
|
||||
|
@ -884,6 +884,10 @@ describe('Page', function() {
|
||||
const response = await page.goto('about:blank');
|
||||
expect(response).toBe(null);
|
||||
}));
|
||||
it('should navigate to empty page with domcontentloaded', SX(async function() {
|
||||
const response = await page.goto(EMPTY_PAGE, {waitUntil: 'domcontentloaded'});
|
||||
expect(response.status).toBe(200);
|
||||
}));
|
||||
it('should navigate to empty page with networkidle0', SX(async function() {
|
||||
const response = await page.goto(EMPTY_PAGE, {waitUntil: 'networkidle0'});
|
||||
expect(response.status).toBe(200);
|
||||
|
Loading…
Reference in New Issue
Block a user