lighthouse 9.5.0-dev.20220906 → 9.5.0-dev.20220908
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/cli/cli-flags.js +17 -0
- package/cli/run.js +2 -2
- package/cli/test/smokehouse/core-tests.js +2 -3
- package/cli/test/smokehouse/report-assert.js +0 -4
- package/cli/test/smokehouse/smokehouse.js +6 -0
- package/core/audits/bootup-time.js +2 -2
- package/core/audits/byte-efficiency/byte-efficiency-audit.js +7 -6
- package/core/audits/byte-efficiency/duplicated-javascript.js +1 -1
- package/core/audits/byte-efficiency/legacy-javascript.js +2 -2
- package/core/audits/byte-efficiency/modern-image-formats.js +5 -5
- package/core/audits/byte-efficiency/offscreen-images.js +4 -4
- package/core/audits/byte-efficiency/render-blocking-resources.js +5 -5
- package/core/audits/byte-efficiency/total-byte-weight.js +1 -1
- package/core/audits/byte-efficiency/unminified-css.js +1 -1
- package/core/audits/byte-efficiency/unused-css-rules.js +1 -1
- package/core/audits/byte-efficiency/unused-javascript.js +4 -4
- package/core/audits/byte-efficiency/uses-long-cache-ttl.js +3 -3
- package/core/audits/byte-efficiency/uses-optimized-images.js +5 -5
- package/core/audits/byte-efficiency/uses-responsive-images-snapshot.js +2 -2
- package/core/audits/byte-efficiency/uses-responsive-images.js +3 -3
- package/core/audits/byte-efficiency/uses-text-compression.js +2 -2
- package/core/audits/critical-request-chains.js +1 -1
- package/core/audits/csp-xss.js +1 -1
- package/core/audits/deprecations.js +2 -2
- package/core/audits/diagnostics.js +7 -7
- package/core/audits/dobetterweb/charset.js +1 -1
- package/core/audits/dobetterweb/uses-http2.js +8 -8
- package/core/audits/errors-in-console.js +2 -2
- package/core/audits/final-screenshot.js +2 -2
- package/core/audits/font-display.js +7 -6
- package/core/audits/image-aspect-ratio.js +3 -3
- package/core/audits/image-size-responsive.js +3 -3
- package/core/audits/installable-manifest.js +1 -1
- package/core/audits/is-on-https.js +3 -3
- package/core/audits/long-tasks.js +4 -4
- package/core/audits/main-thread-tasks.js +1 -1
- package/core/audits/mainthread-work-breakdown.js +1 -1
- package/core/audits/maskable-icon.js +1 -1
- package/core/audits/metrics/cumulative-layout-shift.js +1 -1
- package/core/audits/metrics/experimental-interaction-to-next-paint.js +1 -1
- package/core/audits/metrics/first-contentful-paint-3g.js +1 -1
- package/core/audits/metrics/first-contentful-paint.js +1 -1
- package/core/audits/metrics/first-meaningful-paint.js +1 -1
- package/core/audits/metrics/interactive.js +1 -1
- package/core/audits/metrics/largest-contentful-paint.js +1 -1
- package/core/audits/metrics/max-potential-fid.js +1 -1
- package/core/audits/metrics/speed-index.js +1 -1
- package/core/audits/metrics/total-blocking-time.js +1 -1
- package/core/audits/metrics.js +2 -2
- package/core/audits/network-requests.js +4 -4
- package/core/audits/network-rtt.js +3 -3
- package/core/audits/network-server-latency.js +3 -3
- package/core/audits/no-unload-listeners.js +2 -2
- package/core/audits/performance-budget.js +2 -2
- package/core/audits/predictive-perf.js +8 -8
- package/core/audits/preload-fonts.js +1 -1
- package/core/audits/preload-lcp-image.js +4 -4
- package/core/audits/redirects.js +4 -4
- package/core/audits/resource-summary.js +1 -1
- package/core/audits/screenshot-thumbnails.js +1 -1
- package/core/audits/script-treemap-data.js +5 -5
- package/core/audits/seo/canonical.js +3 -3
- package/core/audits/seo/font-size.js +2 -2
- package/core/audits/seo/http-status-code.js +1 -1
- package/core/audits/seo/is-crawlable.js +1 -2
- package/core/audits/seo/link-text.js +2 -2
- package/core/audits/seo/plugins.js +0 -1
- package/core/audits/seo/robots-txt.js +0 -1
- package/core/audits/seo/tap-targets.js +2 -2
- package/core/audits/server-response-time.js +1 -1
- package/core/audits/service-worker.js +0 -1
- package/core/audits/splash-screen.js +1 -1
- package/core/audits/themed-omnibox.js +1 -1
- package/core/audits/third-party-facades.js +3 -3
- package/core/audits/third-party-summary.js +2 -2
- package/core/audits/timing-budget.js +2 -2
- package/core/audits/unsized-images.js +4 -4
- package/core/audits/user-timings.js +1 -1
- package/core/audits/uses-rel-preconnect.js +12 -10
- package/core/audits/uses-rel-preload.js +6 -6
- package/core/audits/viewport.js +2 -2
- package/core/audits/violation-audit.js +2 -2
- package/core/audits/work-during-interaction.js +4 -4
- package/core/computed/critical-request-chains.js +5 -3
- package/core/computed/image-records.js +5 -3
- package/core/computed/js-bundles.js +2 -1
- package/core/computed/load-simulator.js +3 -5
- package/core/computed/main-resource.js +3 -2
- package/core/computed/main-thread-tasks.js +3 -2
- package/core/computed/manifest-values.js +3 -1
- package/core/computed/metrics/cumulative-layout-shift.js +3 -2
- package/core/computed/metrics/first-contentful-paint-all-frames.js +3 -2
- package/core/computed/metrics/first-contentful-paint.js +4 -3
- package/core/computed/metrics/first-meaningful-paint.js +4 -3
- package/core/computed/metrics/interactive.js +4 -3
- package/core/computed/metrics/lantern-first-contentful-paint.js +3 -2
- package/core/computed/metrics/lantern-first-meaningful-paint.js +4 -3
- package/core/computed/metrics/lantern-interactive.js +4 -3
- package/core/computed/metrics/lantern-largest-contentful-paint.js +4 -3
- package/core/computed/metrics/lantern-max-potential-fid.js +5 -4
- package/core/computed/metrics/lantern-metric.js +6 -6
- package/core/computed/metrics/lantern-speed-index.js +5 -4
- package/core/computed/metrics/lantern-total-blocking-time.js +5 -4
- package/core/computed/metrics/largest-contentful-paint-all-frames.js +3 -2
- package/core/computed/metrics/largest-contentful-paint.js +4 -3
- package/core/computed/metrics/max-potential-fid.js +4 -3
- package/core/computed/metrics/metric.js +3 -3
- package/core/computed/metrics/navigation-metric.js +4 -3
- package/core/computed/metrics/responsiveness.js +3 -2
- package/core/computed/metrics/speed-index.js +5 -4
- package/core/computed/metrics/timing-summary.js +15 -14
- package/core/computed/metrics/total-blocking-time.js +5 -4
- package/core/computed/module-duplication.js +5 -3
- package/core/computed/network-analysis.js +3 -2
- package/core/computed/network-records.js +2 -1
- package/core/computed/page-dependency-graph.js +13 -11
- package/core/computed/processed-navigation.js +2 -1
- package/core/computed/processed-trace.js +2 -1
- package/core/computed/resource-summary.js +4 -3
- package/core/computed/screenshots.js +2 -1
- package/core/computed/speedline.js +3 -2
- package/core/computed/unused-css.js +3 -2
- package/core/computed/unused-javascript-summary.js +2 -1
- package/core/computed/user-timings.js +3 -2
- package/core/computed/viewport-meta.js +2 -1
- package/core/fraggle-rock/gather/navigation-runner.js +3 -3
- package/core/gather/driver/navigation.js +3 -3
- package/core/gather/driver/network-monitor.js +2 -2
- package/core/gather/gather-runner.js +3 -3
- package/core/gather/gatherers/dobetterweb/optimized-images.js +3 -3
- package/core/gather/gatherers/dobetterweb/response-compression.js +3 -3
- package/core/gather/gatherers/dobetterweb/tags-blocking-first-paint.js +1 -1
- package/core/gather/gatherers/inspector-issues.js +1 -1
- package/core/gather/gatherers/link-elements.js +1 -2
- package/core/gather/gatherers/main-document-content.js +1 -1
- package/core/gather/gatherers/script-elements.js +1 -1
- package/core/gather/gatherers/source-maps.js +0 -1
- package/core/gather/gatherers/trace-elements.js +4 -4
- package/core/index.js +3 -3
- package/core/lib/asset-saver.js +4 -4
- package/core/lib/dependency-graph/simulator/network-analyzer.js +2 -2
- package/core/lib/icons.js +0 -2
- package/core/lib/manifest-parser.js +0 -2
- package/core/lib/network-request.js +7 -7
- package/core/lib/{url-shim.js → url-utils.js} +4 -12
- package/package.json +2 -3
- package/report/test/renderer/performance-category-renderer-test.js +0 -1
- package/report/test/renderer/report-renderer-test.js +0 -1
- package/tsconfig.json +1 -1
- package/core/fraggle-rock/replay/stringify-extension.js +0 -104
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import FRGatherer from '../../fraggle-rock/gather/base-gatherer.js';
|
|
8
|
-
import NetworkRecords from '../../computed/network-records.js';
|
|
8
|
+
import {NetworkRecords} from '../../computed/network-records.js';
|
|
9
9
|
import {NetworkRequest} from '../../lib/network-request.js';
|
|
10
10
|
import {pageFunctions} from '../../lib/page-functions.js';
|
|
11
11
|
import DevtoolsLog from './devtools-log.js';
|
|
@@ -18,10 +18,10 @@ import {pageFunctions} from '../../lib/page-functions.js';
|
|
|
18
18
|
import * as RectHelpers from '../../lib/rect-helpers.js';
|
|
19
19
|
import {Sentry} from '../../lib/sentry.js';
|
|
20
20
|
import Trace from './trace.js';
|
|
21
|
-
import ProcessedTrace from '../../computed/processed-trace.js';
|
|
22
|
-
import ProcessedNavigation from '../../computed/processed-navigation.js';
|
|
21
|
+
import {ProcessedTrace} from '../../computed/processed-trace.js';
|
|
22
|
+
import {ProcessedNavigation} from '../../computed/processed-navigation.js';
|
|
23
23
|
import {LighthouseError} from '../../lib/lh-error.js';
|
|
24
|
-
import
|
|
24
|
+
import {Responsiveness} from '../../computed/metrics/responsiveness.js';
|
|
25
25
|
|
|
26
26
|
/** @typedef {{nodeId: number, score?: number, animations?: {name?: string, failureReasonsMask?: number, unsupportedProperties?: string[]}[], type?: string}} TraceElementData */
|
|
27
27
|
|
|
@@ -150,7 +150,7 @@ class TraceElements extends FRGatherer {
|
|
|
150
150
|
static async getResponsivenessElement(trace, context) {
|
|
151
151
|
const {settings} = context;
|
|
152
152
|
try {
|
|
153
|
-
const responsivenessEvent = await
|
|
153
|
+
const responsivenessEvent = await Responsiveness.request({trace, settings}, context);
|
|
154
154
|
if (!responsivenessEvent || responsivenessEvent.name === 'FallbackTiming') return;
|
|
155
155
|
return {nodeId: responsivenessEvent.args.data.nodeId};
|
|
156
156
|
} catch {
|
package/core/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import log from 'lighthouse-logger';
|
|
|
9
9
|
import {Runner} from './runner.js';
|
|
10
10
|
import {CriConnection} from './gather/connections/cri.js';
|
|
11
11
|
import {Config} from './config/config.js';
|
|
12
|
-
import
|
|
12
|
+
import UrlUtils from './lib/url-utils.js';
|
|
13
13
|
import * as fraggleRock from './fraggle-rock/api.js';
|
|
14
14
|
import {Driver} from './gather/driver.js';
|
|
15
15
|
import {initializeConfig} from './fraggle-rock/config/config.js';
|
|
@@ -67,7 +67,7 @@ async function legacyNavigation(url, flags = {}, configJSON, userConnection) {
|
|
|
67
67
|
|
|
68
68
|
// kick off a lighthouse run
|
|
69
69
|
const artifacts = await Runner.gather(() => {
|
|
70
|
-
const requestedUrl =
|
|
70
|
+
const requestedUrl = UrlUtils.normalizeUrl(url);
|
|
71
71
|
return Runner._gatherArtifactsFromBrowser(requestedUrl, options, connection);
|
|
72
72
|
}, options);
|
|
73
73
|
return Runner.audit(artifacts, options);
|
|
@@ -110,7 +110,7 @@ const traceCategories = Driver.traceCategories;
|
|
|
110
110
|
export default lighthouse;
|
|
111
111
|
export {Audit} from './audits/audit.js';
|
|
112
112
|
export {default as Gatherer} from './fraggle-rock/gather/base-gatherer.js';
|
|
113
|
-
export {
|
|
113
|
+
export {NetworkRecords} from './computed/network-records.js';
|
|
114
114
|
export {
|
|
115
115
|
legacyNavigation,
|
|
116
116
|
generateConfig,
|
package/core/lib/asset-saver.js
CHANGED
|
@@ -14,8 +14,8 @@ import log from 'lighthouse-logger';
|
|
|
14
14
|
import {Simulator} from './dependency-graph/simulator/simulator.js';
|
|
15
15
|
import lanternTraceSaver from './lantern-trace-saver.js';
|
|
16
16
|
import {MetricTraceEvents} from './traces/metric-trace-events.js';
|
|
17
|
-
import
|
|
18
|
-
import
|
|
17
|
+
import {NetworkAnalysis} from '../computed/network-analysis.js';
|
|
18
|
+
import {LoadSimulator} from '../computed/load-simulator.js';
|
|
19
19
|
import {LighthouseError} from '../lib/lh-error.js';
|
|
20
20
|
|
|
21
21
|
const {promisify} = util;
|
|
@@ -310,8 +310,8 @@ async function saveLanternNetworkData(devtoolsLog, outputPath) {
|
|
|
310
310
|
/** @type {LH.Audit.Context} */
|
|
311
311
|
// @ts-expect-error - the full audit context isn't needed for analysis.
|
|
312
312
|
const context = {computedCache: new Map()};
|
|
313
|
-
const networkAnalysis = await
|
|
314
|
-
const lanternData =
|
|
313
|
+
const networkAnalysis = await NetworkAnalysis.request(devtoolsLog, context);
|
|
314
|
+
const lanternData = LoadSimulator.convertAnalysisToSaveableLanternData(networkAnalysis);
|
|
315
315
|
|
|
316
316
|
fs.writeFileSync(outputPath, JSON.stringify(lanternData));
|
|
317
317
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import
|
|
7
|
+
import UrlUtils from '../../url-utils.js';
|
|
8
8
|
|
|
9
9
|
const INITIAL_CWD = 14 * 1024;
|
|
10
10
|
|
|
@@ -440,7 +440,7 @@ class NetworkAnalyzer {
|
|
|
440
440
|
// equalWithExcludedFragments is expensive, so check that the resourceUrl starts with the request url first
|
|
441
441
|
return records.find(request =>
|
|
442
442
|
resourceUrl.startsWith(request.url) &&
|
|
443
|
-
|
|
443
|
+
UrlUtils.equalWithExcludedFragments(request.url, resourceUrl)
|
|
444
444
|
);
|
|
445
445
|
}
|
|
446
446
|
|
package/core/lib/icons.js
CHANGED
|
@@ -4,8 +4,6 @@
|
|
|
4
4
|
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import URL from './url-shim.js';
|
|
8
|
-
|
|
9
7
|
/**
|
|
10
8
|
* @param {NonNullable<LH.Artifacts.Manifest['value']>} manifest
|
|
11
9
|
* @return {boolean} Does the manifest have any icons?
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
Trace: ResourceFinish.ts
|
|
53
53
|
*/
|
|
54
54
|
|
|
55
|
-
import
|
|
55
|
+
import UrlUtils from './url-utils.js';
|
|
56
56
|
|
|
57
57
|
// Lightrider X-Header names for timing information.
|
|
58
58
|
// See: _updateTransferSizeForLightrider and _updateTimingsForLightrider.
|
|
@@ -215,7 +215,7 @@ class NetworkRequest {
|
|
|
215
215
|
host: url.hostname,
|
|
216
216
|
securityOrigin: url.origin,
|
|
217
217
|
};
|
|
218
|
-
this.isSecure =
|
|
218
|
+
this.isSecure = UrlUtils.isSecureScheme(this.parsedURL.scheme);
|
|
219
219
|
|
|
220
220
|
this.startTime = data.timestamp;
|
|
221
221
|
|
|
@@ -522,9 +522,9 @@ class NetworkRequest {
|
|
|
522
522
|
*/
|
|
523
523
|
static isNonNetworkRequest(record) {
|
|
524
524
|
// The 'protocol' field in devtools a string more like a `scheme`
|
|
525
|
-
return
|
|
525
|
+
return UrlUtils.isNonNetworkProtocol(record.protocol) ||
|
|
526
526
|
// But `protocol` can fail to be populated if the request fails, so fallback to scheme.
|
|
527
|
-
|
|
527
|
+
UrlUtils.isNonNetworkProtocol(record.parsedURL.scheme);
|
|
528
528
|
}
|
|
529
529
|
|
|
530
530
|
/**
|
|
@@ -535,9 +535,9 @@ class NetworkRequest {
|
|
|
535
535
|
* @return {boolean}
|
|
536
536
|
*/
|
|
537
537
|
static isSecureRequest(record) {
|
|
538
|
-
return
|
|
539
|
-
|
|
540
|
-
|
|
538
|
+
return UrlUtils.isSecureScheme(record.parsedURL.scheme) ||
|
|
539
|
+
UrlUtils.isSecureScheme(record.protocol) ||
|
|
540
|
+
UrlUtils.isLikeLocalhost(record.parsedURL.host) ||
|
|
541
541
|
NetworkRequest.isHstsRequest(record);
|
|
542
542
|
}
|
|
543
543
|
|
|
@@ -4,12 +4,8 @@
|
|
|
4
4
|
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* URL shim so we keep our code DRY
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
7
|
import {Util} from '../util.cjs';
|
|
12
|
-
import {LighthouseError} from '
|
|
8
|
+
import {LighthouseError} from './lh-error.js';
|
|
13
9
|
|
|
14
10
|
/** @typedef {import('./network-request.js').NetworkRequest} NetworkRequest */
|
|
15
11
|
|
|
@@ -43,8 +39,7 @@ function rewriteChromeInternalUrl(url) {
|
|
|
43
39
|
return url.replace(/^chrome:\/\/chrome\//, 'chrome://');
|
|
44
40
|
}
|
|
45
41
|
|
|
46
|
-
|
|
47
|
-
class URLShim extends URL {
|
|
42
|
+
class UrlUtils {
|
|
48
43
|
/**
|
|
49
44
|
* @param {string} url
|
|
50
45
|
* @return {boolean}
|
|
@@ -264,11 +259,8 @@ class URLShim extends URL {
|
|
|
264
259
|
}
|
|
265
260
|
}
|
|
266
261
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
URLShim.INVALID_URL_DEBUG_STRING =
|
|
262
|
+
UrlUtils.INVALID_URL_DEBUG_STRING =
|
|
270
263
|
'Lighthouse was unable to determine the URL of some script executions. ' +
|
|
271
264
|
'It\'s possible a Chrome extension or other eval\'d code is the source.';
|
|
272
265
|
|
|
273
|
-
|
|
274
|
-
export default URLShim;
|
|
266
|
+
export default UrlUtils;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lighthouse",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "9.5.0-dev.
|
|
4
|
+
"version": "9.5.0-dev.20220908",
|
|
5
5
|
"description": "Automated auditing, performance metrics, and best practices for the web.",
|
|
6
6
|
"main": "./core/index.js",
|
|
7
7
|
"bin": {
|
|
@@ -98,7 +98,6 @@
|
|
|
98
98
|
"@build-tracker/cli": "^1.0.0-beta.15",
|
|
99
99
|
"@esbuild-kit/esm-loader": "^2.1.1",
|
|
100
100
|
"@jest/fake-timers": "^28.1.0",
|
|
101
|
-
"@puppeteer/replay": "^0.6.1",
|
|
102
101
|
"@rollup/plugin-alias": "^3.1.2",
|
|
103
102
|
"@rollup/plugin-commonjs": "^20.0.0",
|
|
104
103
|
"@rollup/plugin-dynamic-import-vars": "^1.1.1",
|
|
@@ -160,7 +159,7 @@
|
|
|
160
159
|
"jsdom": "^12.2.0",
|
|
161
160
|
"jsonld": "^5.2.0",
|
|
162
161
|
"jsonlint-mod": "^1.7.6",
|
|
163
|
-
"lighthouse-plugin-publisher-ads": "
|
|
162
|
+
"lighthouse-plugin-publisher-ads": "1.5.7-beta",
|
|
164
163
|
"magic-string": "^0.25.7",
|
|
165
164
|
"mime-types": "^2.1.30",
|
|
166
165
|
"mocha": "^10.0.0",
|
|
@@ -10,7 +10,6 @@ import jsdom from 'jsdom';
|
|
|
10
10
|
|
|
11
11
|
import {Util} from '../../renderer/util.js';
|
|
12
12
|
import {I18n} from '../../renderer/i18n.js';
|
|
13
|
-
import URL from '../../../core/lib/url-shim.js';
|
|
14
13
|
import {DOM} from '../../renderer/dom.js';
|
|
15
14
|
import {DetailsRenderer} from '../../renderer/details-renderer.js';
|
|
16
15
|
import {PerformanceCategoryRenderer} from '../../renderer/performance-category-renderer.js';
|
|
@@ -10,7 +10,6 @@ import jsdom from 'jsdom';
|
|
|
10
10
|
import jestMock from 'jest-mock';
|
|
11
11
|
|
|
12
12
|
import {Util} from '../../renderer/util.js';
|
|
13
|
-
import URL from '../../../core/lib/url-shim.js';
|
|
14
13
|
import {DOM} from '../../renderer/dom.js';
|
|
15
14
|
import {DetailsRenderer} from '../../renderer/details-renderer.js';
|
|
16
15
|
import {CategoryRenderer} from '../../renderer/category-renderer.js';
|
package/tsconfig.json
CHANGED
|
@@ -99,7 +99,7 @@
|
|
|
99
99
|
"core/test/lib/tracehouse/task-summary-test.js",
|
|
100
100
|
"core/test/lib/tracehouse/trace-processor-test.js",
|
|
101
101
|
"core/test/lib/traces/metrics-trace-events-test.js",
|
|
102
|
-
"core/test/lib/url-
|
|
102
|
+
"core/test/lib/url-utils-test.js",
|
|
103
103
|
"core/test/network-records-to-devtools-log-test.js",
|
|
104
104
|
"core/test/runner-test.js",
|
|
105
105
|
"core/test/scoring-test.js",
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright 2022 The Lighthouse Authors. All Rights Reserved.
|
|
3
|
-
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
4
|
-
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import * as PuppeteerReplay from '@puppeteer/replay';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @param {PuppeteerReplay.Schema.Step} step
|
|
11
|
-
* @return {boolean}
|
|
12
|
-
*/
|
|
13
|
-
function isNavigationStep(step) {
|
|
14
|
-
return Boolean(
|
|
15
|
-
step.type === 'navigate' ||
|
|
16
|
-
step.assertedEvents?.some(event => event.type === 'navigation')
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
class LighthouseStringifyExtension extends PuppeteerReplay.PuppeteerStringifyExtension {
|
|
21
|
-
#isProcessingTimespan = false;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* @override
|
|
25
|
-
* @param {PuppeteerReplay.LineWriter} out
|
|
26
|
-
* @param {PuppeteerReplay.Schema.UserFlow} flow
|
|
27
|
-
*/
|
|
28
|
-
async beforeAllSteps(out, flow) {
|
|
29
|
-
out.appendLine(`const fs = require('fs');`);
|
|
30
|
-
|
|
31
|
-
let isMobile = true;
|
|
32
|
-
for (const step of flow.steps) {
|
|
33
|
-
if (step.type !== 'setViewport') continue;
|
|
34
|
-
isMobile = step.isMobile;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
await super.beforeAllSteps(out, flow);
|
|
38
|
-
|
|
39
|
-
const flags = {
|
|
40
|
-
screenEmulation: {
|
|
41
|
-
disabled: true,
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
out.appendLine(`const flags = ${JSON.stringify(flags)}`);
|
|
45
|
-
if (isMobile) {
|
|
46
|
-
out.appendLine(`const config = undefined;`);
|
|
47
|
-
} else {
|
|
48
|
-
// eslint-disable-next-line max-len
|
|
49
|
-
out.appendLine(`const config = (await import('lighthouse/core/config/desktop-config.js')).default;`);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
out.appendLine(`const lhApi = await import('lighthouse/core/fraggle-rock/api.js');`);
|
|
53
|
-
// eslint-disable-next-line max-len
|
|
54
|
-
out.appendLine(`const lhFlow = await lhApi.startFlow(page, {name: ${JSON.stringify(flow.title)}, config, flags});`);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* @override
|
|
59
|
-
* @param {PuppeteerReplay.LineWriter} out
|
|
60
|
-
* @param {PuppeteerReplay.Schema.Step} step
|
|
61
|
-
* @param {PuppeteerReplay.Schema.UserFlow} flow
|
|
62
|
-
*/
|
|
63
|
-
async stringifyStep(out, step, flow) {
|
|
64
|
-
if (step.type === 'setViewport') {
|
|
65
|
-
await super.stringifyStep(out, step, flow);
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const isNavigation = isNavigationStep(step);
|
|
70
|
-
|
|
71
|
-
if (isNavigation) {
|
|
72
|
-
if (this.#isProcessingTimespan) {
|
|
73
|
-
out.appendLine(`await lhFlow.endTimespan();`);
|
|
74
|
-
this.#isProcessingTimespan = false;
|
|
75
|
-
}
|
|
76
|
-
out.appendLine(`await lhFlow.startNavigation();`);
|
|
77
|
-
} else if (!this.#isProcessingTimespan) {
|
|
78
|
-
out.appendLine(`await lhFlow.startTimespan();`);
|
|
79
|
-
this.#isProcessingTimespan = true;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
await super.stringifyStep(out, step, flow);
|
|
83
|
-
|
|
84
|
-
if (isNavigation) {
|
|
85
|
-
out.appendLine(`await lhFlow.endNavigation();`);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* @override
|
|
91
|
-
* @param {PuppeteerReplay.LineWriter} out
|
|
92
|
-
* @param {PuppeteerReplay.Schema.UserFlow} flow
|
|
93
|
-
*/
|
|
94
|
-
async afterAllSteps(out, flow) {
|
|
95
|
-
if (this.#isProcessingTimespan) {
|
|
96
|
-
out.appendLine(`await lhFlow.endTimespan();`);
|
|
97
|
-
}
|
|
98
|
-
out.appendLine(`const lhFlowReport = await lhFlow.generateReport();`);
|
|
99
|
-
out.appendLine(`fs.writeFileSync(__dirname + '/flow.report.html', lhFlowReport)`);
|
|
100
|
-
await super.afterAllSteps(out, flow);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export default LighthouseStringifyExtension;
|