Make prettier JS snippets (#377)

* Make prettier JS snippets

* Conform to CS (about curly brace)

* Apply feedback
This commit is contained in:
Brikou CARRE 2017-08-19 01:46:10 +02:00 committed by Eric Bidelman
parent ae3fedfa91
commit 8f43befcc9
2 changed files with 12 additions and 8 deletions

View File

@ -42,7 +42,6 @@ of `Browser`, open pages, and then manipulate them with [Puppeteer's API](https:
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
@ -60,7 +59,6 @@ Puppeteer sets an initial page size to 800px x 600px, which defines the screensh
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://news.ycombinator.com', {waitUntil: 'networkidle'});

View File

@ -221,7 +221,7 @@ The arguments passed into `console.log` appear as arguments on the event handler
An example of handling `console` event:
```js
page.on('console', (...args) => {
for (let i =0; i < args.length; ++i)
for (let i = 0; i < args.length; ++i)
console.log(`${i}: ${args[i]}`);
});
page.evaluate(() => console.log(5, 'hello', {foo: 'bar'}));
@ -406,7 +406,9 @@ const crypto = require('crypto');
puppeteer.launch().then(async browser => {
let page = await browser.newPage();
page.on('console', console.log);
await page.exposeFunction('md5', text => crypto.createHash('md5').update(text).digest('hex'));
await page.exposeFunction('md5', text =>
crypto.createHash('md5').update(text).digest('hex')
);
await page.evaluate(async () => {
// use window.md5 to compute hashes
let myString = 'PUPPETEER';
@ -761,7 +763,9 @@ const puppeteer = require('puppeteer');
puppeteer.launch().then(async browser => {
let page = await browser.newPage();
let currentURL;
page.waitForSelector('img').then(() => console.log('First URL with image: ' + 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.goto(currentURL);
browser.close();
@ -1065,7 +1069,9 @@ const puppeteer = require('puppeteer');
puppeteer.launch().then(async browser => {
let page = await browser.newPage();
let currentURL;
page.waitForSelector('img').then(() => console.log('First URL with image: ' + 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.goto(currentURL);
browser.close();
@ -1083,7 +1089,7 @@ puppeteer.launch().then(async browser => {
await page.goto('https://google.com');
let inputElement = await page.$('input[type=submit]');
await inputElement.click();
...
// ...
});
```
@ -1235,4 +1241,4 @@ Contains the URL of the response.
[Tracing]: #class-tracing "Tracing"
[ElementHandle]: #class-elementhandle "ElementHandle"
[UIEvent.detail]: https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail "UIEvent.detail"
[Serializable]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable"
[Serializable]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable"