Skip to content

Commit

Permalink
Update puppeteer
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Jul 18, 2020
1 parent 41af229 commit a273065
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 23 deletions.
7 changes: 3 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const {promisify} = require('util');
const fs = require('fs');
const fileUrl = require('file-url');
const puppeteer = require('puppeteer');
const {devicesMap} = require('puppeteer/DeviceDescriptors');
const toughCookie = require('tough-cookie');

const writeFile = promisify(fs.writeFile);
Expand Down Expand Up @@ -216,11 +215,11 @@ const captureWebsite = async (input, options) => {
await page.setViewport(viewportOptions);

if (options.emulateDevice) {
if (!(options.emulateDevice in devicesMap)) {
if (!(options.emulateDevice in puppeteer.devices)) {
throw new Error(`The device name \`${options.emulateDevice}\` is not supported`);
}

await page.emulate(devicesMap[options.emulateDevice]);
await page.emulate(puppeteer.devices[options.emulateDevice]);
}

await page.emulateMediaFeatures([{
Expand Down Expand Up @@ -340,7 +339,7 @@ module.exports.buffer = async (url, options) => captureWebsite(url, {...options,

module.exports.base64 = async (url, options) => captureWebsite(url, {...options, encoding: 'base64'});

module.exports.devices = Object.values(devicesMap).map(device => device.name);
module.exports.devices = Object.values(puppeteer.devices).map(device => device.name);

if (process.env.NODE_ENV === 'test') {
module.exports._startBrowser = puppeteer.launch.bind(puppeteer);
Expand Down
15 changes: 5 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
],
"dependencies": {
"file-url": "^3.0.0",
"puppeteer": "^3.0.4",
"puppeteer": "^5.2.0",
"tough-cookie": "^4.0.0"
},
"devDependencies": {
"@types/puppeteer": "^2.0.1",
"ava": "^2.0.0",
"@types/puppeteer": "^3.0.1",
"ava": "^2.4.0",
"create-test-server": "^3.0.1",
"delay": "^4.1.0",
"image-size": "^0.8.3",
Expand All @@ -51,12 +51,7 @@
"pify": "^5.0.0",
"png-js": "^1.0.0",
"tempy": "^0.5.0",
"tsd": "^0.11.0",
"xo": "^0.30.0"
},
"xo": {
"rules": {
"@typescript-eslint/prefer-readonly-parameter-types": "off"
}
"tsd": "^0.13.1",
"xo": "^0.32.1"
}
}
7 changes: 0 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ It uses [Puppeteer](https://github.com/GoogleChrome/puppeteer) (Chrome) under th

See [capture-website-cli](https://github.com/sindresorhus/capture-website-cli) for the command-line tool.


## Install

```
Expand All @@ -15,7 +14,6 @@ $ npm install capture-website

Note to Linux users: If you get a sandbox-related error, you need to enable [system sandboxing](#im-getting-a-sandbox-related-error).


## Usage

```js
Expand All @@ -26,7 +24,6 @@ const captureWebsite = require('capture-website');
})();
```


## API

### captureWebsite.file(input, outputFilePath, options?)
Expand Down Expand Up @@ -73,7 +70,6 @@ Values: `'url'` `'html'`

Set it to `html` to treat `input` as HTML content.


```js
const captureWebsite = require('capture-website');

Expand Down Expand Up @@ -452,7 +448,6 @@ Type: `string[]`

Devices supported by the `emulateDevice` option.


## Tips

### Capturing multiple screenshots
Expand Down Expand Up @@ -480,7 +475,6 @@ const items = [

*Check out [`filenamify-url`](https://github.com/sindresorhus/filenamify-url) if you need to create a filename from the URL.*


## FAQ

### I'm getting a sandbox-related error
Expand Down Expand Up @@ -508,7 +502,6 @@ const captureWebsite = require('capture-website');

The biggest difference is that Pageres supports capturing multiple screenshots in a single call and it automatically generates the filenames and writes the files. Also, when projects are popular and mature, like Pageres, it becomes harder to make drastic changes. There are many things I would change in Pageres today, but I don't want to risk making lots of breaking changes for such a large userbase before I know whether it will work out or not. So this package is a rethink of how I would have made Pageres had I started it today. I plan to bring some things back to Pageres over time.


## Related

- [capture-website-cli](https://github.com/sindresorhus/capture-website-cli) - CLI for this module
Expand Down
4 changes: 2 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import isPng from 'is-png';
import pify from 'pify';
import PNG from 'png-js';
import createTestServer from 'create-test-server';
import {devicesMap} from 'puppeteer/DeviceDescriptors';
import tempy from 'tempy';
import delay from 'delay';
import toughCookie from 'tough-cookie';
import fileUrl from 'file-url';
import puppeteer from 'puppeteer';
import captureWebsite, {_startBrowser} from '.';

const defaultResponse = (() => {
Expand Down Expand Up @@ -133,7 +133,7 @@ test('`scaleFactor` option', async t => {
});

test('`emulateDevice` option', async t => {
const device = devicesMap['iPhone X'];
const device = puppeteer.devices['iPhone X'];

const size = imageSize(await instance(server.url, {
emulateDevice: device.name
Expand Down

0 comments on commit a273065

Please sign in to comment.