Skip to content

Commit

Permalink
Use ES6 imports
Browse files Browse the repository at this point in the history
  • Loading branch information
NeverMendel committed Feb 1, 2024
1 parent a498b8d commit 84d12f6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
24 changes: 15 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -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] <url>', 'Take a screenshot of a webpage', (yargs) => {
yargs
.usage('$0 [options] <url>', 'Take a screenshot of a webpage', (args) => {
args
.option('width', {
description: 'Viewport width',
type: 'number',
Expand Down Expand Up @@ -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);

Expand All @@ -98,6 +103,7 @@ function takeScreenshot(argv) {
height: argv.height,
},
bindAddress: '0.0.0.0',
headless: "new",
args: [
'--no-sandbox',
'--headless',
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Binary file added screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 84d12f6

Please sign in to comment.