From f797f8c307ff5380c750d3851c0b3d61a5299df5 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Thu, 26 Apr 2018 13:32:40 -0700 Subject: [PATCH] docs(api.md): add explanation to page.waitForNavigation (#2354) Fixes #1860 --- docs/api.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/api.md b/docs/api.md index ed432b35851..350bc150805 100644 --- a/docs/api.md +++ b/docs/api.md @@ -1404,6 +1404,17 @@ Shortcut for [page.mainFrame().waitForFunction(pageFunction[, options[, ...args] - `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. +This resolves when the page navigates to a new URL or reloads. It is useful for when you run code +which will indirectly cause the page to navigate. Consider this example: + +```js +const navigationPromise = page.waitForNavigation(); +await page.click('a.my-link'); // Clicking the link will indirectly cause a navigation +await navigationPromise; // The navigationPromise resolves after navigation has finished +``` + +**NOTE** Usage of the [History API](https://developer.mozilla.org/en-US/docs/Web/API/History_API) to change the URL is considered a navigation. + #### page.waitForSelector(selector[, options]) - `selector` <[string]> A [selector] of an element to wait for - `options` <[Object]> Optional waiting parameters