Skip to content

Commit

Permalink
Rename Page.navigate into Page.goto (puppeteer#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
aslushnikov authored Aug 10, 2017
1 parent fe06c89 commit e1d8a37
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 136 deletions.
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ npm run unit -- --filter=waitFor
...
// Using "fit" to run specific test
fit('should work', SX(async function() {
await response = page.navigate(EMPTY_PAGE);
await response = page.goto(EMPTY_PAGE);
expect(response.ok).toBe(true);
}))
```
Expand All @@ -95,7 +95,7 @@ npm run unit -- --filter=waitFor
...
// Using "xit" to skip specific test
xit('should work', SX(async function() {
await response = page.navigate(EMPTY_PAGE);
await response = page.goto(EMPTY_PAGE);
expect(response.ok).toBe(true);
}))
```
Expand Down Expand Up @@ -136,12 +136,12 @@ Try putting the following script in the `script.js` and running it via `DEBUG=*
const {Browser} = require('puppeteer');
const browser = new Browser();
browser.newPage().then(async page => {
await page.navigate('https://example.com');
await page.goto('https://example.com');
browser.close();
});
```

Tips-n-tricks:
- `DEBUG=*,-*:protocol node script.js` - dump everything BUT protocol messages
- `DEBUG=*:page node script.js` - dump only Page's API calls
- `DEBUG=*:mouse,*:keyboard node script.js` - dump only Mouse and Keyboard API calls
- `DEBUG=*:mouse,*:keyboard node script.js` - dump only Mouse and Keyboard API calls
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const {Browser} = require('puppeteer');
const browser = new Browser();

browser.newPage().then(async page => {
await page.navigate('https://example.com');
await page.goto('https://example.com');
await page.screenshot({path: 'example.png'});
browser.close();
});
Expand Down
59 changes: 30 additions & 29 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
+ [page.frames()](#pageframes)
+ [page.goBack(options)](#pagegobackoptions)
+ [page.goForward(options)](#pagegoforwardoptions)
+ [page.goto(url, options)](#pagegotourl-options)
+ [page.hover(selector)](#pagehoverselector)
+ [page.injectFile(filePath)](#pageinjectfilefilepath)
+ [page.keyboard](#pagekeyboard)
+ [page.mainFrame()](#pagemainframe)
+ [page.mouse](#pagemouse)
+ [page.navigate(url, options)](#pagenavigateurl-options)
+ [page.pdf(options)](#pagepdfoptions)
+ [page.plainText()](#pageplaintext)
+ [page.press(key[, options])](#pagepresskey-options)
Expand Down Expand Up @@ -131,7 +131,7 @@ The following is a typical example of using a Browser class to drive automation:
const {Browser} = require('puppeteer');
const browser = new Browser();
browser.newPage().then(async page => {
await page.navigate('https://google.com');
await page.goto('https://google.com');
// other actions...
browser.close();
});
Expand All @@ -155,7 +155,7 @@ browser.newPage().then(async page => {
page.setUserAgent(iPhone.userAgent),
page.setViewport(iPhone.viewport)
]);
await page.navigate('https://google.com');
await page.goto('https://google.com');
// other actions...
browser.close();
});
Expand All @@ -174,7 +174,7 @@ A typical scenario of using [Browser] is opening a new page and navigating it to
const {Browser} = require('puppeteer');
const browser = new Browser();
browser.newPage().then(async page => {
await page.navigate('https://example.com');
await page.goto('https://example.com');
browser.close();
});
```
Expand Down Expand Up @@ -241,7 +241,7 @@ An example of creating a page, navigating it to a URL and saving screenshot as `
const {Browser} = require('puppeteer');
const browser = new Browser();
browser.newPage().then(async page =>
await page.navigate('https://example.com');
await page.goto('https://example.com');
await page.screenshot({path: 'screenshot.png'});
browser.close();
});
Expand Down Expand Up @@ -407,6 +407,26 @@ can not go back, resolves to null.

Navigate to the next page in history.

#### page.goto(url, options)
- `url` <[string]> URL to navigate page to
- `options` <[Object]> Navigation parameters which might have the following properties:
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds.
- `waitUntil` <[string]> When to consider navigation succeeded, defaults to `load`. Could be either:
- `load` - consider navigation to be finished when the `load` event is fired.
- `networkidle` - consider navigation to be finished when the network activity stays "idle" for at least `networkIdleTimeout`ms.
- `networkIdleInflight` <[number]> Maximum amount of inflight requests which are considered "idle". Takes effect only with `waitUntil: 'networkidle'` parameter.
- `networkIdleTimeout` <[number]> A timeout to wait before completing navigation. Takes effect only with `waitUntil: 'networkidle'` parameter.
- 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.

The `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 main resource failed to load.

> **NOTE** `page.goto` either throw or return a main resource response. The only exception is navigation to `about:blank`, which would succeed and return `null`.

#### page.hover(selector)
- `selector` <[string]> A query [selector] to search for element to hover. If there are multiple elements satisfying the selector, the first will be hovered.
- returns: <[Promise]> Promise which resolves when the element matching `selector` is successfully hovered. Promise gets rejected if there's no element matching `selector`.
Expand All @@ -432,25 +452,6 @@ Page is guaranteed to have a main frame which persists during navigations.

- returns: <[Mouse]>

#### page.navigate(url, options)
- `url` <[string]> URL to navigate page to
- `options` <[Object]> Navigation parameters which might have the following properties:
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds.
- `waitUntil` <[string]> When to consider navigation succeeded, defaults to `load`. Could be either:
- `load` - consider navigation to be finished when the `load` event is fired.
- `networkidle` - consider navigation to be finished when the network activity stays "idle" for at least `networkIdleTimeout`ms.
- `networkIdleInflight` <[number]> Maximum amount of inflight requests which are considered "idle". Takes effect only with `waitUntil: 'networkidle'` parameter.
- `networkIdleTimeout` <[number]> A timeout to wait before completing navigation. Takes effect only with `waitUntil: 'networkidle'` parameter.
- 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.

The `page.navigate` 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 main resource failed to load.

> **NOTE** `page.navigate` either throw or return a main resource response. The only exception is navigation to `about:blank`, which would succeed and return `null`.
#### page.pdf(options)
- `options` <[Object]> Options object which might have the following properties:
- `path` <[string]> The file path to save the PDF to. If `path` is a relative path, then it is resolved relative to [current working directory](https://nodejs.org/api/process.html#process_process_cwd).
Expand Down Expand Up @@ -583,7 +584,7 @@ browser.newPage().then(async page =>
else
interceptedRequest.continue();
});
await page.navigate('https://example.com');
await page.goto('https://example.com');
browser.close();
});
```
Expand Down Expand Up @@ -714,7 +715,7 @@ browser.newPage().then(async page => {
let currentURL;
page.waitForSelector('img').then(() => console.log('First URL with image: ' + currentURL));
for (currentURL of ['https://example.com', 'https://google.com', 'https://bbc.com'])
await page.navigate(currentURL);
await page.goto(currentURL);
browser.close();
});
```
Expand Down Expand Up @@ -812,7 +813,7 @@ You can use [`tracing.start`](#tracingstartoptions) and [`tracing.stop`](#tracin

```js
await page.tracing.start({path: 'trace.json'});
await page.navigate('https://www.google.com');
await page.goto('https://www.google.com');
await page.tracing.stop();
```

Expand Down Expand Up @@ -876,7 +877,7 @@ const {Browser} = new require('.');
const browser = new Browser({headless: true});

browser.newPage().then(async page => {
await page.navigate('https://www.google.com/chrome/browser/canary.html');
await page.goto('https://www.google.com/chrome/browser/canary.html');
dumpFrameTree(page.mainFrame(), '');
browser.close();

Expand Down Expand Up @@ -1029,7 +1030,7 @@ browser.newPage().then(async page => {
let currentURL;
page.waitForSelector('img').then(() => console.log('First URL with image: ' + currentURL));
for (currentURL of ['https://example.com', 'https://google.com', 'https://bbc.com'])
await page.navigate(currentURL);
await page.goto(currentURL);
browser.close();
});
```
Expand Down
2 changes: 1 addition & 1 deletion examples/block-images.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ await page.setRequestInterceptor(request => {
else
request.continue();
});
await page.navigate('https://bbc.com');
await page.goto('https://bbc.com');
await page.screenshot({path: 'news.png', fullPage: true});
browser.close();

Expand Down
2 changes: 1 addition & 1 deletion examples/detect-sniff.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const browser = new Browser();

const page = await browser.newPage();
await page.evaluateOnNewDocument(sniffDetector);
await page.navigate('https://www.google.com', {waitUntil: 'networkidle'});
await page.goto('https://www.google.com', {waitUntil: 'networkidle'});
console.log('Sniffed: ' + (await page.evaluate(() => !!navigator.sniffed)));
browser.close();

Expand Down
2 changes: 1 addition & 1 deletion examples/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const {Browser} = require('puppeteer');
const browser = new Browser();

const page = await browser.newPage();
await page.navigate('https://news.ycombinator.com', {waitUntil: 'networkidle'});
await page.goto('https://news.ycombinator.com', {waitUntil: 'networkidle'});
// page.pdf() is currently supported only in headless mode.
// @see https://bugs.chromium.org/p/chromium/issues/detail?id=753118
await page.pdf({
Expand Down
2 changes: 1 addition & 1 deletion examples/screenshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const {Browser} = require('puppeteer');
const browser = new Browser();

browser.newPage().then(async page => {
await page.navigate('http://example.com');
await page.goto('http://example.com');
await page.screenshot({path: 'example.png'});
browser.close();
});
4 changes: 2 additions & 2 deletions lib/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Page extends EventEmitter {
if (ignoreHTTPSErrors)
await client.send('Security.setOverrideCertificateErrors', {override: true});
const page = new Page(client, ignoreHTTPSErrors, screenshotTaskQueue);
await page.navigate('about:blank');
await page.goto('about:blank');
// Initialize default page size.
await page.setViewport({width: 800, height: 600});
return page;
Expand Down Expand Up @@ -265,7 +265,7 @@ class Page extends EventEmitter {
* @param {!Object=} options
* @return {!Promise<?Response>}
*/
async navigate(url, options) {
async goto(url, options) {
const watcher = new NavigatorWatcher(this._client, this._ignoreHTTPSErrors, options);
const responses = new Map();
const listener = helper.addEventListener(this._networkManager, NetworkManager.Events.Response, response => responses.set(response.url, response));
Expand Down
2 changes: 1 addition & 1 deletion phantom_shim/WebPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ class WebPage {
callback.call(null, status);
this.loadingProgress = 0;
};
this._page.navigate(url).then(response => handleNavigation(null, response))
this._page.goto(url).then(response => handleNavigation(null, response))
.catch(e => handleNavigation(e, null));
}

Expand Down
Loading

0 comments on commit e1d8a37

Please sign in to comment.