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

feat: use serverless-chrome binary #31

Merged
merged 3 commits into from
Aug 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# joytocode/lighthouse-lambda

Run [Google Chrome Lighthouse](https://github.com/GoogleChrome/lighthouse) on [AWS Lambda](https://aws.amazon.com/lambda/).

## Versions

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.

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

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.

## Lambda function

```js
Expand Down Expand Up @@ -60,7 +60,7 @@ $ docker run --rm -v "$PWD":/var/task lambci/lambda:build-nodejs8.10 bash -c "rm
$ 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"
```

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

## API
Expand All @@ -71,10 +71,14 @@ Same parameters as [Using Lighthouse programmatically](https://github.com/Google

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

- `chrome`: an instance of [`chromeLauncher.launch()`](https://github.com/GoogleChrome/chrome-launcher#launchopts).
- `chrome`: an instance of [`chromeLauncher.launch()`](https://github.com/GoogleChrome/chrome-launcher#launchopts), remember to call `chrome.kill()` in the end.
- `log`: an instance of [lighthouse-logger](https://github.com/GoogleChrome/lighthouse/tree/master/lighthouse-logger) (only if you set `options.logLevel`).
- `start()`: a function to start the scan which returns a `Promise` of Lighthouse results.

## Credits

`lighthouse-lambda` uses the Headless Chrome binary (stable version) from [@serverless-chrome/lambda](https://www.npmjs.com/package/@serverless-chrome/lambda).

## License

[MIT](LICENSE)
16 changes: 0 additions & 16 deletions lib/checksum.js

This file was deleted.

29 changes: 0 additions & 29 deletions lib/chromeConfig.js

This file was deleted.

16 changes: 12 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
const path = require('path')
const chromePath = require.resolve('@serverless-chrome/lambda/dist/headless-chromium')
const chromeLauncher = require('chrome-launcher')
const lighthouse = require('lighthouse')
const chromeConfig = require('./chromeConfig')

const defaultFlags = [
'--headless',
'--disable-dev-shm-usage',
'--disable-gpu',
'--no-zygote',
'--no-sandbox',
'--single-process',
'--hide-scrollbars'
]

module.exports = function createLighthouse (url, options = {}, config) {
options.output = options.output || 'html'
const log = options.logLevel ? require('lighthouse-logger') : null
if (log) {
log.setLevel(options.logLevel)
}
const chromeFlags = chromeConfig.flags.concat(options.chromeFlags || [])
const chromePath = path.join(chromeConfig.binary.binPath, chromeConfig.binary.fileName)
const chromeFlags = options.chromeFlags || defaultFlags
return chromeLauncher.launch({ chromeFlags, chromePath })
.then((chrome) => {
options.port = chrome.port
Expand Down
97 changes: 0 additions & 97 deletions lib/postinstall.js

This file was deleted.

Loading