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

Commit dd3865b

Browse files
authored
feat: use serverless-chrome binary (#31)
* feat: use serverless-chrome binary * chore: allow to set url for test function * chore: log more result info for test function
1 parent 926b24c commit dd3865b

10 files changed

Lines changed: 154 additions & 880 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` 3.x will use `lighthouse` 3.x.
68

79
This README is for version 3.x. To see older versions, visit:
@@ -14,8 +16,6 @@ This README is for version 3.x. To see older versions, visit:
1416
$ npm install lighthouse-lambda --save
1517
```
1618

17-
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.
18-
1919
## Lambda function
2020

2121
```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,10 +71,14 @@ 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()`: a function to start the scan which returns a `Promise` of Lighthouse results.
7777

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

8084
[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')
4-
const chromeConfig = require('./chromeConfig')
4+
5+
const defaultFlags = [
6+
'--headless',
7+
'--disable-dev-shm-usage',
8+
'--disable-gpu',
9+
'--no-zygote',
10+
'--no-sandbox',
11+
'--single-process',
12+
'--hide-scrollbars'
13+
]
514

615
module.exports = function createLighthouse (url, options = {}, config) {
716
options.output = options.output || 'html'
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)