mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
doc: add await to browser.close in usage examples (#797)
browser.close returns a promise after f398e69
, so it should be awaited.
This commit is contained in:
parent
e2cad568d6
commit
aa58f25bc1
@ -47,7 +47,7 @@ const puppeteer = require('puppeteer');
|
|||||||
await page.goto('https://example.com');
|
await page.goto('https://example.com');
|
||||||
await page.screenshot({path: 'example.png'});
|
await page.screenshot({path: 'example.png'});
|
||||||
|
|
||||||
browser.close();
|
await browser.close();
|
||||||
})();
|
})();
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ const puppeteer = require('puppeteer');
|
|||||||
await page.goto('https://news.ycombinator.com', {waitUntil: 'networkidle'});
|
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();
|
await browser.close();
|
||||||
})();
|
})();
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ const puppeteer = require('puppeteer');
|
|||||||
|
|
||||||
console.log('Dimensions:', dimensions);
|
console.log('Dimensions:', dimensions);
|
||||||
|
|
||||||
browser.close();
|
await browser.close();
|
||||||
})();
|
})();
|
||||||
```
|
```
|
||||||
|
|
||||||
|
26
docs/api.md
26
docs/api.md
@ -162,7 +162,7 @@ puppeteer.launch().then(async browser => {
|
|||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
await page.goto('https://www.google.com');
|
await page.goto('https://www.google.com');
|
||||||
// other actions...
|
// other actions...
|
||||||
browser.close();
|
await browser.close();
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -205,7 +205,7 @@ const puppeteer = require('puppeteer');
|
|||||||
puppeteer.launch().then(async browser => {
|
puppeteer.launch().then(async browser => {
|
||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
await page.goto('https://example.com');
|
await page.goto('https://example.com');
|
||||||
browser.close();
|
await browser.close();
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -240,7 +240,7 @@ puppeteer.launch().then(async browser => {
|
|||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
await page.goto('https://example.com');
|
await page.goto('https://example.com');
|
||||||
await page.screenshot({path: 'screenshot.png'});
|
await page.screenshot({path: 'screenshot.png'});
|
||||||
browser.close();
|
await browser.close();
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -441,7 +441,7 @@ puppeteer.launch().then(async browser => {
|
|||||||
await page.emulate(iPhone);
|
await page.emulate(iPhone);
|
||||||
await page.goto('https://www.google.com');
|
await page.goto('https://www.google.com');
|
||||||
// other actions...
|
// other actions...
|
||||||
browser.close();
|
await browser.close();
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -520,7 +520,7 @@ puppeteer.launch().then(async browser => {
|
|||||||
const myHash = await window.md5(myString);
|
const myHash = await window.md5(myString);
|
||||||
console.log(`md5 of ${myString} is ${myHash}`);
|
console.log(`md5 of ${myString} is ${myHash}`);
|
||||||
});
|
});
|
||||||
browser.close();
|
await browser.close();
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -548,7 +548,7 @@ puppeteer.launch().then(async browser => {
|
|||||||
const content = await window.readfile('/etc/hosts');
|
const content = await window.readfile('/etc/hosts');
|
||||||
console.log(content);
|
console.log(content);
|
||||||
});
|
});
|
||||||
browser.close();
|
await browser.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
```
|
```
|
||||||
@ -775,7 +775,7 @@ puppeteer.launch().then(async browser => {
|
|||||||
interceptedRequest.continue();
|
interceptedRequest.continue();
|
||||||
});
|
});
|
||||||
await page.goto('https://example.com');
|
await page.goto('https://example.com');
|
||||||
browser.close();
|
await browser.close();
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -877,7 +877,7 @@ puppeteer.launch().then(async browser => {
|
|||||||
const watchDog = page.waitForFunction('window.innerWidth < 100');
|
const watchDog = page.waitForFunction('window.innerWidth < 100');
|
||||||
page.setViewport({width: 50, height: 50});
|
page.setViewport({width: 50, height: 50});
|
||||||
await watchDog;
|
await watchDog;
|
||||||
browser.close();
|
await browser.close();
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
Shortcut for [page.mainFrame().waitForFunction(pageFunction[, options[, ...args]])](#framewaitforfunctionpagefunction-options-args).
|
Shortcut for [page.mainFrame().waitForFunction(pageFunction[, options[, ...args]])](#framewaitforfunctionpagefunction-options-args).
|
||||||
@ -915,7 +915,7 @@ puppeteer.launch().then(async browser => {
|
|||||||
.then(() => console.log('First URL with image: ' + currentURL));
|
.then(() => console.log('First URL with image: ' + currentURL));
|
||||||
for (currentURL of ['https://example.com', 'https://google.com', 'https://bbc.com'])
|
for (currentURL of ['https://example.com', 'https://google.com', 'https://bbc.com'])
|
||||||
await page.goto(currentURL);
|
await page.goto(currentURL);
|
||||||
browser.close();
|
await browser.close();
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
Shortcut for [page.mainFrame().waitForSelector(selector[, options])](#framewaitforselectorselector-options).
|
Shortcut for [page.mainFrame().waitForSelector(selector[, options])](#framewaitforselectorselector-options).
|
||||||
@ -1051,7 +1051,7 @@ puppeteer.launch().then(async browser => {
|
|||||||
page.on('dialog', async dialog => {
|
page.on('dialog', async dialog => {
|
||||||
console.log(dialog.message());
|
console.log(dialog.message());
|
||||||
await dialog.dismiss();
|
await dialog.dismiss();
|
||||||
browser.close();
|
await browser.close();
|
||||||
});
|
});
|
||||||
page.evaluate(() => alert('1'));
|
page.evaluate(() => alert('1'));
|
||||||
});
|
});
|
||||||
@ -1093,7 +1093,7 @@ puppeteer.launch().then(async browser => {
|
|||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
await page.goto('https://www.google.com/chrome/browser/canary.html');
|
await page.goto('https://www.google.com/chrome/browser/canary.html');
|
||||||
dumpFrameTree(page.mainFrame(), '');
|
dumpFrameTree(page.mainFrame(), '');
|
||||||
browser.close();
|
await browser.close();
|
||||||
|
|
||||||
function dumpFrameTree(frame, indent) {
|
function dumpFrameTree(frame, indent) {
|
||||||
console.log(indent + frame.url());
|
console.log(indent + frame.url());
|
||||||
@ -1229,7 +1229,7 @@ puppeteer.launch().then(async browser => {
|
|||||||
const watchDog = page.mainFrame().waitForFunction('window.innerWidth < 100');
|
const watchDog = page.mainFrame().waitForFunction('window.innerWidth < 100');
|
||||||
page.setViewport({width: 50, height: 50});
|
page.setViewport({width: 50, height: 50});
|
||||||
await watchDog;
|
await watchDog;
|
||||||
browser.close();
|
await browser.close();
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -1256,7 +1256,7 @@ puppeteer.launch().then(async browser => {
|
|||||||
.then(() => console.log('First URL with image: ' + currentURL));
|
.then(() => console.log('First URL with image: ' + currentURL));
|
||||||
for (currentURL of ['https://example.com', 'https://google.com', 'https://bbc.com'])
|
for (currentURL of ['https://example.com', 'https://google.com', 'https://bbc.com'])
|
||||||
await page.goto(currentURL);
|
await page.goto(currentURL);
|
||||||
browser.close();
|
await browser.close();
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ page.on('request', request => {
|
|||||||
await page.goto('https://www.reuters.com/');
|
await page.goto('https://www.reuters.com/');
|
||||||
await page.screenshot({path: 'news.png', fullPage: true});
|
await page.screenshot({path: 'news.png', fullPage: true});
|
||||||
|
|
||||||
browser.close();
|
await browser.close();
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
@ -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'});
|
await page.goto('https://www.chromestatus.com/features', {waitUntil: 'networkidle'});
|
||||||
|
|
||||||
browser.close();
|
await browser.close();
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
@ -41,6 +41,6 @@ await page.evaluateOnNewDocument(sniffDetector);
|
|||||||
await page.goto('https://www.google.com', {waitUntil: 'networkidle'});
|
await page.goto('https://www.google.com', {waitUntil: 'networkidle'});
|
||||||
console.log('Sniffed: ' + (await page.evaluate(() => !!navigator.sniffed)));
|
console.log('Sniffed: ' + (await page.evaluate(() => !!navigator.sniffed)));
|
||||||
|
|
||||||
browser.close();
|
await browser.close();
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
@ -30,6 +30,6 @@ await page.pdf({
|
|||||||
format: 'letter'
|
format: 'letter'
|
||||||
});
|
});
|
||||||
|
|
||||||
browser.close();
|
await browser.close();
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
@ -28,6 +28,6 @@ const browser = await puppeteer.launch({
|
|||||||
});
|
});
|
||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
await page.goto('https://google.com');
|
await page.goto('https://google.com');
|
||||||
browser.close();
|
await browser.close();
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
@ -26,6 +26,6 @@ const page = await browser.newPage();
|
|||||||
await page.emulate(devices['iPhone 6']);
|
await page.emulate(devices['iPhone 6']);
|
||||||
await page.goto('https://www.nytimes.com/');
|
await page.goto('https://www.nytimes.com/');
|
||||||
await page.screenshot({path: 'full.png', fullPage: true});
|
await page.screenshot({path: 'full.png', fullPage: true});
|
||||||
browser.close();
|
await browser.close();
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
@ -25,6 +25,6 @@ const page = await browser.newPage();
|
|||||||
await page.goto('http://example.com');
|
await page.goto('http://example.com');
|
||||||
await page.screenshot({path: 'example.png'});
|
await page.screenshot({path: 'example.png'});
|
||||||
|
|
||||||
browser.close();
|
await browser.close();
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
@ -37,6 +37,6 @@ const links = await page.evaluate(() => {
|
|||||||
return anchors.map(anchor => anchor.textContent);
|
return anchors.map(anchor => anchor.textContent);
|
||||||
});
|
});
|
||||||
console.log(links.join('\n'));
|
console.log(links.join('\n'));
|
||||||
browser.close();
|
await browser.close();
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
Loading…
Reference in New Issue
Block a user