@browserless/lighthouse 9.8.4 → 9.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/README.md +4 -0
- package/package.json +4 -8
- package/src/get-config.js +14 -0
- package/src/index.js +11 -67
- package/src/lighthouse.js +4 -19
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright © 2019 Microlink <hello@microlink.io> (microlink.io)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -16,6 +16,10 @@ Using npm:
|
|
|
16
16
|
npm install @browserless/lighthouse --save
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
See [browseress#lighthouse](https://browserless.js.org/#/?id=runing-lighthouse).
|
|
22
|
+
|
|
19
23
|
## License
|
|
20
24
|
|
|
21
25
|
**@browserless/lighthouse** © [Microlink](https://microlink.io), released under the [MIT](https://github.com/microlinkhq/browserless/blob/master/LICENSE.md) License.<br>
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@browserless/lighthouse",
|
|
3
3
|
"description": "Browserless Lighthouse integration using puppeteer.",
|
|
4
4
|
"homepage": "https://browserless.js.org",
|
|
5
|
-
"version": "9.
|
|
5
|
+
"version": "9.9.2",
|
|
6
6
|
"main": "src",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -24,14 +24,10 @@
|
|
|
24
24
|
"stats"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"
|
|
28
|
-
"debug-logfmt": "~1.0.4",
|
|
29
|
-
"lighthouse": "~9.6.8",
|
|
30
|
-
"p-retry": "~4.6.1",
|
|
31
|
-
"p-timeout": "~4.1.0",
|
|
32
|
-
"serialize-error": "~8.1.0"
|
|
27
|
+
"lighthouse": "~10.0.0"
|
|
33
28
|
},
|
|
34
29
|
"devDependencies": {
|
|
30
|
+
"@browserless/test": "^9.7.2",
|
|
35
31
|
"ava": "3",
|
|
36
32
|
"browserless": "latest"
|
|
37
33
|
},
|
|
@@ -50,5 +46,5 @@
|
|
|
50
46
|
"timeout": "30s",
|
|
51
47
|
"verbose": true
|
|
52
48
|
},
|
|
53
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "77201bfd691e447ebd5580a8466fe77a82a039d2"
|
|
54
50
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const preset = name =>
|
|
4
|
+
name
|
|
5
|
+
? import(`lighthouse/core/config/${name}-config.js`)
|
|
6
|
+
.then(mod => mod.default)
|
|
7
|
+
.catch(() => undefined)
|
|
8
|
+
: undefined
|
|
9
|
+
|
|
10
|
+
module.exports = async ({ preset: presetName, ...settings } = {}) => {
|
|
11
|
+
const config = (await preset(presetName)) || { extends: 'lighthouse:default' }
|
|
12
|
+
if (Object.keys(settings).length > 0) config.settings = { ...config.settings, ...settings }
|
|
13
|
+
return config
|
|
14
|
+
}
|
package/src/index.js
CHANGED
|
@@ -1,76 +1,20 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { ensureError, browserTimeout } = require('@browserless/errors')
|
|
4
|
-
const debug = require('debug-logfmt')('browserless:lighthouse')
|
|
5
|
-
const pTimeout = require('p-timeout')
|
|
6
|
-
const pRetry = require('p-retry')
|
|
7
|
-
|
|
8
3
|
const lighthouse = require('./lighthouse')
|
|
4
|
+
const getConfig = require('./get-config')
|
|
9
5
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
const baseConfig = presetName
|
|
14
|
-
? require(`lighthouse/lighthouse-core/config/${presetName}-config.js`)
|
|
15
|
-
: { extends: 'lighthouse:default' }
|
|
16
|
-
|
|
17
|
-
return { ...baseConfig, settings: { ...baseConfig.settings, ...settings } }
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// See https://github.com/GoogleChrome/lighthouse/blob/master/docs/readme.md#configuration
|
|
21
|
-
const getFlags = (
|
|
22
|
-
browser,
|
|
23
|
-
{ disableStorageReset = true, logLevel = 'error', output = 'json' }
|
|
24
|
-
) => ({
|
|
25
|
-
disableStorageReset,
|
|
26
|
-
logLevel,
|
|
27
|
-
output,
|
|
28
|
-
port: new URL(browser.wsEndpoint()).port
|
|
29
|
-
})
|
|
6
|
+
module.exports = getBrowserless => async (url, { output = 'json', timeout, ...opts } = {}) => {
|
|
7
|
+
let teardown
|
|
8
|
+
const browserless = await getBrowserless(fn => (teardown = fn))
|
|
30
9
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
logLevel,
|
|
37
|
-
output,
|
|
38
|
-
retry = 2,
|
|
39
|
-
timeout = 30000,
|
|
40
|
-
...opts
|
|
41
|
-
} = {}
|
|
42
|
-
) => {
|
|
43
|
-
const browserlessPromise = getBrowserless()
|
|
44
|
-
const config = getConfig(opts)
|
|
45
|
-
let isRejected = false
|
|
46
|
-
|
|
47
|
-
async function run () {
|
|
48
|
-
const browserless = await browserlessPromise
|
|
49
|
-
const browser = await browserless.browser()
|
|
50
|
-
const flags = await getFlags(browser, { disableStorageReset, logLevel, output })
|
|
51
|
-
const { value, reason, isFulfilled } = await lighthouse({ url, flags, config })
|
|
52
|
-
if (isFulfilled) return value
|
|
53
|
-
throw ensureError(reason)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const task = () =>
|
|
57
|
-
pRetry(run, {
|
|
58
|
-
retries: retry,
|
|
59
|
-
onFailedAttempt: async error => {
|
|
60
|
-
if (error.name === 'AbortError') throw error
|
|
61
|
-
if (isRejected) throw new AbortError()
|
|
62
|
-
await (await browserlessPromise).respawn()
|
|
63
|
-
const { message, attemptNumber, retriesLeft } = error
|
|
64
|
-
debug('retry', { attemptNumber, retriesLeft, message })
|
|
65
|
-
}
|
|
10
|
+
const fn = page => async () =>
|
|
11
|
+
lighthouse({
|
|
12
|
+
config: await getConfig({ ...opts, output }),
|
|
13
|
+
page,
|
|
14
|
+
url
|
|
66
15
|
})
|
|
67
16
|
|
|
68
|
-
const result = await
|
|
69
|
-
|
|
70
|
-
throw browserTimeout({ timeout })
|
|
71
|
-
})
|
|
72
|
-
|
|
17
|
+
const result = await browserless.withPage(fn, { timeout })()
|
|
18
|
+
if (teardown) await teardown()
|
|
73
19
|
return result
|
|
74
20
|
}
|
|
75
|
-
|
|
76
|
-
module.exports.getConfig = getConfig
|
package/src/lighthouse.js
CHANGED
|
@@ -1,23 +1,8 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const lighthouse = require('lighthouse')
|
|
3
|
+
const lighthouse = require('lighthouse/core/index.cjs')
|
|
5
4
|
|
|
6
|
-
module.exports = async ({ url,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const value = flags.output === 'json' ? lhr : report
|
|
10
|
-
|
|
11
|
-
return {
|
|
12
|
-
isFulfilled: true,
|
|
13
|
-
isRejected: false,
|
|
14
|
-
value
|
|
15
|
-
}
|
|
16
|
-
} catch (error) {
|
|
17
|
-
return {
|
|
18
|
-
isFulfilled: false,
|
|
19
|
-
isRejected: true,
|
|
20
|
-
reason: serializeError(error)
|
|
21
|
-
}
|
|
22
|
-
}
|
|
5
|
+
module.exports = async ({ url, config, page }) => {
|
|
6
|
+
const { lhr, report } = await lighthouse(url, undefined, config, page)
|
|
7
|
+
return config.settings.output === 'json' ? lhr : report
|
|
23
8
|
}
|