@browserless/lighthouse 9.8.4 → 9.9.0
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/README.md +4 -0
- package/package.json +4 -8
- package/src/get-config.js +14 -0
- package/src/index.js +16 -61
- package/src/lighthouse.js +4 -19
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.0",
|
|
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": "a563e7bc8f30e8d5a2c3d19e8a50ca0bf7bfad3e"
|
|
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,31 @@
|
|
|
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')
|
|
9
|
-
|
|
10
|
-
const { AbortError } = pRetry
|
|
11
|
-
|
|
12
|
-
const getConfig = ({ preset: presetName, ...settings } = {}) => {
|
|
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
|
-
}
|
|
4
|
+
const getConfig = require('./get-config')
|
|
19
5
|
|
|
20
6
|
// 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
|
-
) => ({
|
|
7
|
+
const getFlags = ({ disableStorageReset = true, logLevel = 'error', output = 'json' }) => ({
|
|
25
8
|
disableStorageReset,
|
|
26
9
|
logLevel,
|
|
27
|
-
output
|
|
28
|
-
port: new URL(browser.wsEndpoint()).port
|
|
10
|
+
output
|
|
29
11
|
})
|
|
30
12
|
|
|
31
|
-
module.exports = async (
|
|
13
|
+
module.exports = getBrowserless => async (
|
|
32
14
|
url,
|
|
33
|
-
{
|
|
34
|
-
disableStorageReset,
|
|
35
|
-
getBrowserless = require('browserless'),
|
|
36
|
-
logLevel,
|
|
37
|
-
output,
|
|
38
|
-
retry = 2,
|
|
39
|
-
timeout = 30000,
|
|
40
|
-
...opts
|
|
41
|
-
} = {}
|
|
15
|
+
{ timeout, disableStorageReset, logLevel, output, ...opts } = {}
|
|
42
16
|
) => {
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
}
|
|
17
|
+
let teardown
|
|
18
|
+
const browserless = await getBrowserless(fn => (teardown = fn))
|
|
19
|
+
|
|
20
|
+
const fn = page => async () =>
|
|
21
|
+
lighthouse({
|
|
22
|
+
config: await getConfig(opts),
|
|
23
|
+
flags: getFlags({ disableStorageReset, logLevel, output }),
|
|
24
|
+
page,
|
|
25
|
+
url
|
|
66
26
|
})
|
|
67
27
|
|
|
68
|
-
const result = await
|
|
69
|
-
|
|
70
|
-
throw browserTimeout({ timeout })
|
|
71
|
-
})
|
|
72
|
-
|
|
28
|
+
const result = await browserless.withPage(fn, { timeout })()
|
|
29
|
+
if (teardown) await teardown()
|
|
73
30
|
return result
|
|
74
31
|
}
|
|
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, flags, config }) => {
|
|
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, flags, config, page }) => {
|
|
6
|
+
const { lhr, report } = await lighthouse(url, flags, config, page)
|
|
7
|
+
return flags.output === 'json' ? lhr : report
|
|
23
8
|
}
|