@browserless/lighthouse 13.1.7 → 13.6.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.
Files changed (2) hide show
  1. package/package.json +4 -3
  2. 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.7",
5
+ "version": "13.6.2",
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.7",
39
+ "@browserless/test": "13.6.2",
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": "cb9a0c6fc11176da209ba9bc33bca5a47c3aabbe"
57
+ "gitHead": "7c7c6fee9e82050887d5499ed9dc3bac16c88c42"
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
- const { lhr, report } = await lighthouse(url, flags, config, page)
7
- return config.settings.output === 'json' ? lhr : report
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