diff --git a/index.js b/index.js index 3e950cc..e1d2db6 100644 --- a/index.js +++ b/index.js @@ -1,13 +1,18 @@ -const puppeteer = require('puppeteer'); -var yargs = require('yargs'); -const delay = require('delay'); -const fs = require('fs'); -const path = require('path'); +import puppeteer from 'puppeteer'; +import _yargs from 'yargs'; +import delay from 'delay'; +import fs from 'fs'; +import path from 'path'; + +const yargs = _yargs; + +const maxYargsWidth = 130 +const yargsWidth = Math.min(yargs.terminalWidth, maxYargsWidth) let argv = yargs(process.argv.slice(2)) .detectLocale(false) - .usage('$0 [options] ', 'Take a screenshot of a webpage', (yargs) => { - yargs + .usage('$0 [options] ', 'Take a screenshot of a webpage', (args) => { + args .option('width', { description: 'Viewport width', type: 'number', @@ -79,14 +84,14 @@ let argv = yargs(process.argv.slice(2)) ) .example( '$0 --cookiesFile=cookies.json https://google.com', - 'Load the cookies from cookies.json, take a screenshot of https://google.com and save it as screenshot.png' + 'Load cookies from cookies.json, take a screenshot of https://google.com and save it as screenshot.png' ); }) .help('h') .alias('h', 'help') .version() .alias('version', 'v') - .wrap(Math.min(yargs.terminalWidth(), 130)).argv; + .wrap(yargsWidth).argv; takeScreenshot(argv); @@ -98,6 +103,7 @@ function takeScreenshot(argv) { height: argv.height, }, bindAddress: '0.0.0.0', + headless: "new", args: [ '--no-sandbox', '--headless', diff --git a/package.json b/package.json index a7bb09f..56301c9 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "2.0.0", "description": "Node.js script to take screenshots of webpages with Chrome headless and Puppeteer", "main": "index.js", + "type": "module", "dependencies": { "delay": "^5.0.0", "fs": "0.0.1-security", diff --git a/screenshot.png b/screenshot.png new file mode 100644 index 0000000..96e6331 Binary files /dev/null and b/screenshot.png differ