@browserless/lighthouse 13.1.7 → 13.1.8
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/package.json +4 -3
- package/src/lighthouse.js +20 -2
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@browserless/lighthouse",
|
|
3
3
|
"description": "Run Google Lighthouse audits on websites using headless Chrome. Get performance, accessibility, and SEO metrics.",
|
|
4
4
|
"homepage": "https://browserless.js.org",
|
|
5
|
-
"version": "13.1.
|
|
5
|
+
"version": "13.1.8",
|
|
6
6
|
"main": "src",
|
|
7
7
|
"author": {
|
|
8
8
|
"email": "hello@microlink.io",
|
|
@@ -32,10 +32,11 @@
|
|
|
32
32
|
"web-vitals"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
+
"@browserless/errors": "13.1.7",
|
|
35
36
|
"lighthouse": "~13.4.0"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
38
|
-
"@browserless/test": "13.1.
|
|
39
|
+
"@browserless/test": "13.1.8",
|
|
39
40
|
"ava": "5"
|
|
40
41
|
},
|
|
41
42
|
"engines": {
|
|
@@ -53,5 +54,5 @@
|
|
|
53
54
|
"timeout": "2m",
|
|
54
55
|
"workerThreads": false
|
|
55
56
|
},
|
|
56
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "c47bf305151f14340462c59ae0f47aadeb993e16"
|
|
57
58
|
}
|
package/src/lighthouse.js
CHANGED
|
@@ -1,8 +1,26 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
const errors = require('@browserless/errors')
|
|
3
4
|
const lighthouse = require('lighthouse/core/index.cjs')
|
|
4
5
|
|
|
6
|
+
// Lighthouse instruments each phase with performance marks (via marky). When
|
|
7
|
+
// the browser context is torn down mid-run, lighthouse's teardown calls
|
|
8
|
+
// `performance.measure` for a phase whose start mark never fired, throwing a
|
|
9
|
+
// `SyntaxError: The "start lh:…" performance mark has not been set`. That
|
|
10
|
+
// message masks the real cause (a destroyed context), so it would otherwise
|
|
11
|
+
// escape the retry machinery as an opaque error. Map it back to a
|
|
12
|
+
// context-disconnected error to let `withPage` recreate the context and retry.
|
|
13
|
+
const isPerfMarkError = error =>
|
|
14
|
+
error?.message?.endsWith('performance mark has not been set') ?? false
|
|
15
|
+
|
|
5
16
|
module.exports = async ({ url, config, flags, page }) => {
|
|
6
|
-
|
|
7
|
-
|
|
17
|
+
try {
|
|
18
|
+
const { lhr, report } = await lighthouse(url, flags, config, page)
|
|
19
|
+
return config.settings.output === 'json' ? lhr : report
|
|
20
|
+
} catch (error) {
|
|
21
|
+
if (isPerfMarkError(error)) throw errors.contextDisconnected()
|
|
22
|
+
throw error
|
|
23
|
+
}
|
|
8
24
|
}
|
|
25
|
+
|
|
26
|
+
module.exports.isPerfMarkError = isPerfMarkError
|