puppeteer-screenshot-cli
Advanced tools
Comparing version 1.4.2 to 1.5.0
module.exports = { | ||
"env": { | ||
"es6": true, | ||
"node": true | ||
}, | ||
"parserOptions": { | ||
"ecmaVersion": 2017 | ||
}, | ||
"extends": "eslint:recommended", | ||
"rules": { | ||
"indent": [ | ||
"error", | ||
2 | ||
], | ||
"linebreak-style": [ | ||
"error", | ||
"unix" | ||
], | ||
"quotes": [ | ||
"error", | ||
"single" | ||
], | ||
"semi": [ | ||
"error", | ||
"always" | ||
] | ||
} | ||
"extends": "makina", | ||
}; |
1.5.0 / 2021-01-29 | ||
================== | ||
* Bump lodash, acorn & https-proxy-agent | ||
* Add `--useragent` to set user agent | ||
1.4.3 / 2019-09-11 | ||
================== | ||
* Setup and enforce eslint-config-makina as ESLint ruleset | ||
* Upgrade Puppeteer for security concerns | ||
1.4.2 / 2019-01-03 | ||
@@ -3,0 +15,0 @@ ================== |
55
index.js
#!/usr/bin/env node | ||
const puppeteer = require('puppeteer'); | ||
const EOL = '\n'; | ||
const argsDef = [ | ||
{ name: 'url', alias: 'u', type: String, description: 'URL to navigate page to. The url should include scheme, e.g. https://.' + EOL, defaultOption: true }, | ||
{ name: 'output', alias: 'o', type: String, description: 'The file path to save the image to. If path is a relative path, then it is resolved relative to current working directory. If no path is provided, the image won\'t be saved to the disk.' + EOL }, | ||
{ name: 'selector', alias: 's', type: String, description: 'A CSS selector of an element to wait for. \n[italic]{Default: body}' + EOL }, | ||
{ name: 'type', alias: 't', type: String, description: 'Specify screenshot type, can be either jpeg or png. \n[italic]{Default: png}' + EOL }, | ||
{ name: 'quality', alias: 'q', type: Number, description: 'The quality of the image, between 0-100. Not applicable to png images.' + EOL }, | ||
{ name: 'width', alias: 'w', type: Number, description: 'Viewport width in pixels \n[italic]{Default: 800}' + EOL }, | ||
{ name: 'height', alias: 'h', type: Number, description: 'Viewport height in pixels \n[italic]{Default: 600}' + EOL }, | ||
{ name: 'timeout', type: Number, description: 'Maximum time to wait for in milliseconds. \n[italic]{Default: 30000}' + EOL }, | ||
{ name: 'fullPage', alias: 'f', type: Boolean, description: 'When true, takes a screenshot of the full scrollable page. \n[italic]{Defaults: false}.' + EOL }, | ||
{ name: 'noheadless', type: Boolean, description: 'Allow disabling headless mode. \n[italic]{Default: false}' + EOL}, | ||
{ name: 'help', alias: '?', type: Boolean, description: 'This help' + EOL }, | ||
/* eslint-disable no-multi-spaces */ | ||
{ name: 'url', alias: 'u', type: String, description: `URL to navigate page to. The url should include scheme, e.g. https://.${EOL}`, defaultOption: true }, | ||
{ name: 'output', alias: 'o', type: String, description: `The file path to save the image to. If path is a relative path, then it is resolved relative to current working directory. If no path is provided, the image won't be saved to the disk.${EOL}` }, | ||
{ name: 'selector', alias: 's', type: String, description: `A CSS selector of an element to wait for. \n[italic]{Default: body}${EOL}` }, | ||
{ name: 'type', alias: 't', type: String, description: `Specify screenshot type, can be either jpeg or png. \n[italic]{Default: png}${EOL}` }, | ||
{ name: 'quality', alias: 'q', type: Number, description: `The quality of the image, between 0-100. Not applicable to png images.${EOL}` }, | ||
{ name: 'width', alias: 'w', type: Number, description: `Viewport width in pixels \n[italic]{Default: 800}${EOL}` }, | ||
{ name: 'height', alias: 'h', type: Number, description: `Viewport height in pixels \n[italic]{Default: 600}${EOL}` }, | ||
{ name: 'useragent', type: String, description: `The user agent of the browser \n[italic]{Default: undefined}${EOL}` }, | ||
{ name: 'timeout', type: Number, description: `Maximum time to wait for in milliseconds. \n[italic]{Default: 30000}${EOL}` }, | ||
{ name: 'fullPage', alias: 'f', type: Boolean, description: `When true, takes a screenshot of the full scrollable page. \n[italic]{Defaults: false}.${EOL}` }, | ||
{ name: 'noheadless', type: Boolean, description: `Allow disabling headless mode. \n[italic]{Default: false}${EOL}` }, | ||
{ name: 'help', alias: '?', type: Boolean, description: `This help${EOL}` }, | ||
/* eslint-enable no-multi-spaces */ | ||
]; | ||
@@ -23,3 +27,3 @@ | ||
const doCapture = async function ({ | ||
const doCapture = async function doCapture ({ | ||
url, | ||
@@ -31,5 +35,6 @@ output, | ||
selector = 'body', | ||
width = 800, | ||
height = 600, | ||
timeout = 30000, | ||
width = 800, | ||
height = 600, | ||
useragent = undefined, | ||
timeout = 30000, | ||
fullPage = false, | ||
@@ -43,21 +48,25 @@ }) { | ||
try { | ||
if (useragent) { | ||
await page.setUserAgent(useragent); | ||
} | ||
await page.setViewport({ width, height }); | ||
await page.goto(url, { waitUntil: [ 'load', 'networkidle0' ] }); | ||
await page.goto(url, { waitUntil: ['load', 'networkidle0'] }); | ||
await page.waitForSelector(selector, { visible: true, timeout }); | ||
output = output === '-' ? undefined : output; | ||
type = type === 'jpg' ? 'jpeg' : type; | ||
const outputPath = output === '-' ? undefined : output; | ||
const picture = await page.screenshot({ | ||
type, quality, fullPage, | ||
path: output, | ||
type: type === 'jpg' ? 'jpeg' : type, | ||
quality, | ||
fullPage, | ||
path: outputPath, | ||
clip: !fullPage && await (await page.$(selector)).boundingBox(), | ||
}); | ||
if (!output) { | ||
if (!outputPath) { | ||
process.stdout.write(picture); | ||
} | ||
} catch (error) { | ||
@@ -74,3 +83,3 @@ await browser.close(); | ||
if (args.help || !args.url) { | ||
!args.help && process.stderr.write('No url provided.' + EOL); | ||
!args.help && process.stderr.write(`No url provided.${EOL}`); | ||
process.stderr.write(usage); | ||
@@ -77,0 +86,0 @@ process.exitCode = 1; |
{ | ||
"name": "puppeteer-screenshot-cli", | ||
"version": "1.4.2", | ||
"version": "1.5.0", | ||
"engines": { | ||
@@ -23,7 +23,11 @@ "node": ">=6.4.0" | ||
"command-line-usage": "~4.1.0", | ||
"puppeteer": "~1.0.0" | ||
"puppeteer": "~1.19.0" | ||
}, | ||
"scripts": { | ||
"version": "git changelog -t $npm_package_version && git add CHANGELOG.md" | ||
}, | ||
"devDependencies": { | ||
"eslint": "~6.3.0", | ||
"eslint-config-makina": "~1.0.1" | ||
} | ||
} |
8371
2
72
+ Addeddebug@4.4.0(transitive)
+ Addedmime@2.6.0(transitive)
+ Addedpuppeteer@1.19.0(transitive)
+ Addedws@6.2.3(transitive)
- Removedmime@1.6.0(transitive)
- Removedpuppeteer@1.0.0(transitive)
- Removedultron@1.1.1(transitive)
- Removedws@3.3.3(transitive)
Updatedpuppeteer@~1.19.0