Skip to content

Commit

Permalink
doc: add await to browser.close in usage examples (puppeteer#797)
Browse files Browse the repository at this point in the history
browser.close returns a promise after f398e69, so it should be awaited.
  • Loading branch information
cohesively authored and JoelEinbinder committed Sep 16, 2017
1 parent e2cad56 commit aa58f25
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 24 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const puppeteer = require('puppeteer');
await page.goto('https://example.com');
await page.screenshot({path: 'example.png'});

browser.close();
await browser.close();
})();
```

Expand All @@ -64,7 +64,7 @@ const puppeteer = require('puppeteer');
await page.goto('https://news.ycombinator.com', {waitUntil: 'networkidle'});
await page.pdf({path: 'hn.pdf', format: 'A4'});

browser.close();
await browser.close();
})();
```

Expand All @@ -91,7 +91,7 @@ const puppeteer = require('puppeteer');

console.log('Dimensions:', dimensions);

browser.close();
await browser.close();
})();
```

Expand Down
26 changes: 13 additions & 13 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ puppeteer.launch().then(async browser => {
const page = await browser.newPage();
await page.goto('https://www.google.com');
// other actions...
browser.close();
await browser.close();
});
```

Expand Down Expand Up @@ -205,7 +205,7 @@ const puppeteer = require('puppeteer');
puppeteer.launch().then(async browser => {
const page = await browser.newPage();
await page.goto('https://example.com');
browser.close();
await browser.close();
});
```

Expand Down Expand Up @@ -240,7 +240,7 @@ puppeteer.launch().then(async browser => {
const page = await browser.newPage();
await page.goto('https://example.com');
await page.screenshot({path: 'screenshot.png'});
browser.close();
await browser.close();
});
```

Expand Down Expand Up @@ -441,7 +441,7 @@ puppeteer.launch().then(async browser => {
await page.emulate(iPhone);
await page.goto('https://www.google.com');
// other actions...
browser.close();
await browser.close();
});
```

Expand Down Expand Up @@ -520,7 +520,7 @@ puppeteer.launch().then(async browser => {
const myHash = await window.md5(myString);
console.log(`md5 of ${myString} is ${myHash}`);
});
browser.close();
await browser.close();
});
```

Expand Down Expand Up @@ -548,7 +548,7 @@ puppeteer.launch().then(async browser => {
const content = await window.readfile('/etc/hosts');
console.log(content);
});
browser.close();
await browser.close();
});

```
Expand Down Expand Up @@ -775,7 +775,7 @@ puppeteer.launch().then(async browser => {
interceptedRequest.continue();
});
await page.goto('https://example.com');
browser.close();
await browser.close();
});
```

Expand Down Expand Up @@ -877,7 +877,7 @@ puppeteer.launch().then(async browser => {
const watchDog = page.waitForFunction('window.innerWidth < 100');
page.setViewport({width: 50, height: 50});
await watchDog;
browser.close();
await browser.close();
});
```
Shortcut for [page.mainFrame().waitForFunction(pageFunction[, options[, ...args]])](#framewaitforfunctionpagefunction-options-args).
Expand Down Expand Up @@ -915,7 +915,7 @@ puppeteer.launch().then(async browser => {
.then(() => console.log('First URL with image: ' + currentURL));
for (currentURL of ['https://example.com', 'https://google.com', 'https://bbc.com'])
await page.goto(currentURL);
browser.close();
await browser.close();
});
```
Shortcut for [page.mainFrame().waitForSelector(selector[, options])](#framewaitforselectorselector-options).
Expand Down Expand Up @@ -1051,7 +1051,7 @@ puppeteer.launch().then(async browser => {
page.on('dialog', async dialog => {
console.log(dialog.message());
await dialog.dismiss();
browser.close();
await browser.close();
});
page.evaluate(() => alert('1'));
});
Expand Down Expand Up @@ -1093,7 +1093,7 @@ puppeteer.launch().then(async browser => {
const page = await browser.newPage();
await page.goto('https://www.google.com/chrome/browser/canary.html');
dumpFrameTree(page.mainFrame(), '');
browser.close();
await browser.close();

function dumpFrameTree(frame, indent) {
console.log(indent + frame.url());
Expand Down Expand Up @@ -1229,7 +1229,7 @@ puppeteer.launch().then(async browser => {
const watchDog = page.mainFrame().waitForFunction('window.innerWidth < 100');
page.setViewport({width: 50, height: 50});
await watchDog;
browser.close();
await browser.close();
});
```

Expand All @@ -1256,7 +1256,7 @@ puppeteer.launch().then(async browser => {
.then(() => console.log('First URL with image: ' + currentURL));
for (currentURL of ['https://example.com', 'https://google.com', 'https://bbc.com'])
await page.goto(currentURL);
browser.close();
await 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 @@ -32,7 +32,7 @@ page.on('request', request => {
await page.goto('https://www.reuters.com/');
await page.screenshot({path: 'news.png', fullPage: true});

browser.close();
await browser.close();

})();

2 changes: 1 addition & 1 deletion examples/custom-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ await listenFor('app-ready'); // Listen for "app-ready" custom event on page loa

await page.goto('https://www.chromestatus.com/features', {waitUntil: 'networkidle'});

browser.close();
await browser.close();

})();
2 changes: 1 addition & 1 deletion examples/detect-sniff.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ await page.evaluateOnNewDocument(sniffDetector);
await page.goto('https://www.google.com', {waitUntil: 'networkidle'});
console.log('Sniffed: ' + (await page.evaluate(() => !!navigator.sniffed)));

browser.close();
await browser.close();

})();
2 changes: 1 addition & 1 deletion examples/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ await page.pdf({
format: 'letter'
});

browser.close();
await browser.close();

})();
2 changes: 1 addition & 1 deletion examples/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ const browser = await puppeteer.launch({
});
const page = await browser.newPage();
await page.goto('https://google.com');
browser.close();
await browser.close();

})();
2 changes: 1 addition & 1 deletion examples/screenshot-fullpage.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ const page = await browser.newPage();
await page.emulate(devices['iPhone 6']);
await page.goto('https://www.nytimes.com/');
await page.screenshot({path: 'full.png', fullPage: true});
browser.close();
await browser.close();

})();
2 changes: 1 addition & 1 deletion examples/screenshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ const page = await browser.newPage();
await page.goto('http://example.com');
await page.screenshot({path: 'example.png'});

browser.close();
await browser.close();

})();
2 changes: 1 addition & 1 deletion examples/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ const links = await page.evaluate(() => {
return anchors.map(anchor => anchor.textContent);
});
console.log(links.join('\n'));
browser.close();
await browser.close();

})();

0 comments on commit aa58f25

Please sign in to comment.