Skip to content
This repository was archived by the owner on Mar 14, 2020. It is now read-only.

Commit 2687f7c

Browse files
authored
feat(v2): use serverless-chrome binary (#32)
1 parent 4ad09cf commit 2687f7c

10 files changed

Lines changed: 303 additions & 1036 deletions

File tree

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# joytocode/lighthouse-lambda
2+
23
Run [Google Chrome Lighthouse](https://github.com/GoogleChrome/lighthouse) on [AWS Lambda](https://aws.amazon.com/lambda/).
34

45
## Versions
6+
57
Since version 2.x, `lighthouse-lambda` has the same major version of [lighthouse](https://www.npmjs.com/package/lighthouse). For example, `lighthouse-lambda` 2.x will use `lighthouse` 2.x.
68

79
This README is for version 2.x. To see latest version, visit https://github.com/joytocode/lighthouse-lambda.
@@ -12,8 +14,6 @@ This README is for version 2.x. To see latest version, visit https://github.com/
1214
$ npm install lighthouse-lambda@archived-v2 --save
1315
```
1416

15-
The postinstall script of `lighthouse-lambda` will download a Headless Chrome binary if it does not already exist. The binary is from [joytocode/headless-chrome-builder](https://github.com/joytocode/headless-chrome-builder) and is tested to make sure it works with Lighthouse.
16-
1717
## Lambda function
1818

1919
```js
@@ -60,7 +60,7 @@ $ docker run --rm -v "$PWD":/var/task lambci/lambda:build-nodejs8.10 bash -c "rm
6060
$ docker run --rm -v "$PWD":/var/task lambci/lambda:build-nodejs8.10 bash -c "rm -f *.zip && zip lambda.zip -r node_modules index.js package.json"
6161
```
6262

63-
- The file will be big (at least 80MB), so you need to upload it to S3 then deploy to Lambda from S3.
63+
- The file will be big (at least 75MB), so you need to upload it to S3 then deploy to Lambda from S3.
6464
- You should allocate at least 512 MB memory and 15 seconds timeout to the function.
6565

6666
## API
@@ -71,12 +71,16 @@ Same parameters as [Using Lighthouse programmatically](https://github.com/Google
7171

7272
Returns a `Promise` of an Object with the following fields:
7373

74-
- `chrome`: an instance of [`chromeLauncher.launch()`](https://github.com/GoogleChrome/chrome-launcher#launchopts).
74+
- `chrome`: an instance of [`chromeLauncher.launch()`](https://github.com/GoogleChrome/chrome-launcher#launchopts), remember to call `chrome.kill()` in the end.
7575
- `log`: an instance of [lighthouse-logger](https://github.com/GoogleChrome/lighthouse/tree/master/lighthouse-logger) (only if you set `options.logLevel`).
7676
- `start(options)`: a function to start the scan which returns a `Promise` of Lighthouse results.
7777
- `options.saveArtifacts`: a flag to indicate whether result artifacts should be saved (default: `false`).
7878
- `createReport(results)`: a function to create html report from Lighthouse results.
7979

80+
## Credits
81+
82+
`lighthouse-lambda` uses the Headless Chrome binary (stable version) from [@serverless-chrome/lambda](https://www.npmjs.com/package/@serverless-chrome/lambda).
83+
8084
## License
8185

8286
[MIT](LICENSE)

lib/checksum.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

lib/chromeConfig.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

lib/index.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
1-
const path = require('path')
1+
const chromePath = require.resolve('@serverless-chrome/lambda/dist/headless-chromium')
22
const chromeLauncher = require('chrome-launcher')
33
const lighthouse = require('lighthouse')
44
const ReportGenerator = require('lighthouse/lighthouse-core/report/v2/report-generator')
5-
const chromeConfig = require('./chromeConfig')
5+
6+
const defaultFlags = [
7+
'--headless',
8+
'--disable-dev-shm-usage',
9+
'--disable-gpu',
10+
'--no-zygote',
11+
'--no-sandbox',
12+
'--single-process',
13+
'--hide-scrollbars'
14+
]
615

716
module.exports = function createLighthouse (url, options = {}, config) {
817
const log = options.logLevel ? require('lighthouse-logger') : null
918
if (log) {
1019
log.setLevel(options.logLevel)
1120
}
12-
const chromeFlags = chromeConfig.flags.concat(options.chromeFlags || [])
13-
const chromePath = path.join(chromeConfig.binary.binPath, chromeConfig.binary.fileName)
21+
const chromeFlags = options.chromeFlags || defaultFlags
1422
return chromeLauncher.launch({ chromeFlags, chromePath })
1523
.then((chrome) => {
1624
options.port = chrome.port

lib/postinstall.js

Lines changed: 0 additions & 97 deletions
This file was deleted.

0 commit comments

Comments
 (0)