From 8f43befcc94d353d2c24c4dd325cc9dfe29438bb Mon Sep 17 00:00:00 2001 From: Brikou CARRE Date: Sat, 19 Aug 2017 01:46:10 +0200 Subject: [PATCH] Make prettier JS snippets (#377) * Make prettier JS snippets * Conform to CS (about curly brace) * Apply feedback --- README.md | 2 -- docs/api.md | 18 ++++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 8f83d0b7d53..e40e6192f9d 100644 --- a/README.md +++ b/README.md @@ -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'}); diff --git a/docs/api.md b/docs/api.md index 917767bd504..ff971c33733 100644 --- a/docs/api.md +++ b/docs/api.md @@ -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" \ No newline at end of file +[Serializable]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable"