diff --git a/docs/api.md b/docs/api.md index 700371a8..ccb9a85d 100644 --- a/docs/api.md +++ b/docs/api.md @@ -21,7 +21,7 @@ - [page.viewportSize()](#pagesize) - [page.evaluate(fun, args)](#pageevaluatefun-args) - [page.evaluateOnInitialized(fun, args)](#pageevaluateoninitializedfun-args) - - [page.screenshot(type[, clipRect])](#pagescreenshottype-cliprect) + - [page.screenshot([options])](#pagescreenshottype-cliprect) - [page.printToPDF(filePath[, options])](#pageprinttopdffilepath-options) - [page.plainText()](#pageplaintext) - [page.title()](#pagetitle) @@ -146,19 +146,23 @@ Pages could be closed by `page.close()` method. - `args` [<Array>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) Arguments to pass to `fun` - returns: [<Promise<Object>>](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise) Promise which resolves to function -#### page.screenshot(type[, clipRect]) +#### page.screenshot([options]) -- `type` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) Specify screenshot type, could be either `jpeg` or `png`. -- `clipRect` [<Object>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) An object which specifies clipping region of the page. Should have the following fields: - - `x` [<number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) x-coordinate of top-left corner of clip area - - `y` [<number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) y-coordinate of top-left corner of clip area - - `width` [<number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) width of clipping area - - `height` [<number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) height of clipping area +- `options` [<Object>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) Options object which might have the following properties: + - `path` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) The file path to save the image to. The screenshot type will be inferred from file extension. + - `type` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) Specify screenshot type, could be either `jpeg` or `png`. + - `quality` [<number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) The quality of the image, between 0-100. Not applicable to `.jpg` images. + - `fullPage` [<boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type) When true, takes a screenshot of the full scrollable page. + - `clip` [<Object>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) An object which specifies clipping region of the page. Should have the following fields: + - `x` [<number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) x-coordinate of top-left corner of clip area + - `y` [<number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) y-coordinate of top-left corner of clip area + - `width` [<number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) width of clipping area + - `height` [<number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) height of clipping area - returns: [<Promise<Buffer>>](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise) Promise which resolves to buffer with captured screenshot #### page.printToPDF(filePath[, options]) -- `filePath` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) The file path to save image to. The screenshot type will be inferred from file extension +- `filePath` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) The file path to save the image to. The screenshot type will be inferred from file extension - `options` [<Object>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) Options object which might have the following properties: - `scale` [<number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) - `displayHeaderFooter` [<boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type) diff --git a/examples/screenshot.js b/examples/screenshot.js index 5b6e378b..35b3581b 100644 --- a/examples/screenshot.js +++ b/examples/screenshot.js @@ -14,11 +14,11 @@ * limitations under the License. */ -var Browser = require('../lib/Browser'); -var browser = new Browser(); +const Browser = require('../lib/Browser'); +const browser = new Browser(); browser.newPage().then(async page => { await page.navigate('http://example.com'); - await page.saveScreenshot('example.png'); + const screenshot = await page.screenshot({path: 'example.png'}); browser.close(); }); diff --git a/package.json b/package.json index 380857f8..3242cc0b 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,9 @@ "version": "0.0.1", "description": "", "main": "index.js", + "engines": { + "node": ">=7.10.0" + }, "scripts": { "test-puppeteer": "jasmine test/test.js", "test-phantom": "python third_party/phantomjs/test/run-tests.py",