lighthouse 9.5.0-dev.20220621 → 9.5.0-dev.20220624

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 (30) hide show
  1. package/lighthouse-cli/bin.js +8 -2
  2. package/lighthouse-cli/test/smokehouse/__snapshots__/report-assert-test.js.snap +43 -0
  3. package/lighthouse-cli/test/smokehouse/report-assert-test.js +96 -30
  4. package/lighthouse-cli/test/smokehouse/report-assert.js +36 -35
  5. package/lighthouse-core/audits/byte-efficiency/unused-javascript.js +1 -1
  6. package/lighthouse-core/config/config-helpers.js +15 -0
  7. package/lighthouse-core/fraggle-rock/config/config.js +45 -1
  8. package/lighthouse-core/fraggle-rock/gather/driver.js +13 -5
  9. package/lighthouse-core/fraggle-rock/gather/session.js +23 -67
  10. package/lighthouse-core/gather/driver/navigation.js +1 -1
  11. package/lighthouse-core/gather/driver/network-monitor.js +19 -81
  12. package/lighthouse-core/gather/driver/target-manager.js +110 -45
  13. package/lighthouse-core/gather/driver.js +24 -16
  14. package/lighthouse-core/gather/gatherers/devtools-log.js +7 -11
  15. package/lighthouse-core/gather/gatherers/full-page-screenshot.js +1 -1
  16. package/lighthouse-core/index.js +24 -9
  17. package/lighthouse-core/lib/cdt/Common.js +13 -0
  18. package/lighthouse-core/lib/cdt/Platform.js +3 -0
  19. package/lighthouse-core/lib/cdt/generated/ParsedURL.js +178 -0
  20. package/lighthouse-core/lib/cdt/generated/SourceMap.js +155 -62
  21. package/lighthouse-core/lib/network-recorder.js +9 -18
  22. package/package.json +2 -2
  23. package/third-party/devtools-tests/README.md +14 -0
  24. package/third-party/devtools-tests/e2e/lighthouse/generate-report_test.ts +29 -0
  25. package/third-party/devtools-tests/e2e/lighthouse/indexeddb-warning_test.ts +29 -0
  26. package/third-party/devtools-tests/e2e/resources/lighthouse/lighthouse-storage.html +11 -0
  27. package/third-party/download-content-shell/README.md +1 -0
  28. package/third-party/download-content-shell/download-content-shell.js +6 -1
  29. package/types/gatherer.d.ts +5 -2
  30. package/types/protocol.d.ts +26 -17
@@ -9,9 +9,16 @@ const log = require('lighthouse-logger');
9
9
  const NetworkRequest = require('./network-request.js');
10
10
  const EventEmitter = require('events').EventEmitter;
11
11
 
12
- /** @typedef {'requeststarted'|'requestfinished'} NetworkRecorderEvent */
12
+ /**
13
+ * @typedef {{
14
+ * requeststarted: [NetworkRequest],
15
+ * requestfinished: [NetworkRequest],
16
+ * }} NetworkRecorderEventMap
17
+ */
18
+ /** @typedef {LH.Protocol.StrictEventEmitterClass<NetworkRecorderEventMap>} RequestEmitter */
19
+ const RequestEventEmitter = /** @type {RequestEmitter} */ (EventEmitter);
13
20
 
14
- class NetworkRecorder extends EventEmitter {
21
+ class NetworkRecorder extends RequestEventEmitter {
15
22
  /**
16
23
  * Creates an instance of NetworkRecorder.
17
24
  */
@@ -35,22 +42,6 @@ class NetworkRecorder extends EventEmitter {
35
42
  return Array.from(this._records);
36
43
  }
37
44
 
38
- /**
39
- * @param {NetworkRecorderEvent} event
40
- * @param {*} listener
41
- */
42
- on(event, listener) {
43
- return super.on(event, listener);
44
- }
45
-
46
- /**
47
- * @param {NetworkRecorderEvent} event
48
- * @param {*} listener
49
- */
50
- once(event, listener) {
51
- return super.once(event, listener);
52
- }
53
-
54
45
  /**
55
46
  * Listener for the DevTools SDK NetworkManager's RequestStarted event, which includes both
56
47
  * web socket and normal request creation.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lighthouse",
3
- "version": "9.5.0-dev.20220621",
3
+ "version": "9.5.0-dev.20220624",
4
4
  "description": "Automated auditing, performance metrics, and best practices for the web.",
5
5
  "main": "./lighthouse-core/index.js",
6
6
  "bin": {
@@ -132,7 +132,7 @@
132
132
  "archiver": "^3.0.0",
133
133
  "c8": "^7.4.0",
134
134
  "chalk": "^2.4.1",
135
- "chrome-devtools-frontend": "1.0.922924",
135
+ "chrome-devtools-frontend": "1.0.1012379",
136
136
  "concurrently": "^6.4.0",
137
137
  "conventional-changelog-cli": "^2.1.1",
138
138
  "cpy": "^8.1.2",
@@ -0,0 +1,14 @@
1
+ # Devtools e2e Tests
2
+
3
+ These tests are rolled into the Chromium DevTools Frontend codebase. They "belong" to the devtools frontend, but are truly defined in this Lighthouse repo.
4
+
5
+ Run with `sh lighthouse-core/test/devtools-tests/test-locally.sh`.
6
+
7
+ See `lighthouse-core/test/chromium-web-tests/README.md` for more.
8
+
9
+ ## Sync
10
+
11
+ ```sh
12
+ rsync -ahvz --exclude='OWNERS' --exclude='BUILD.gn' ~/src/devtools/devtools-frontend/test/e2e/lighthouse/ third-party/devtools-tests/e2e/lighthouse/
13
+ rsync -ahvz --exclude='OWNERS' --exclude='BUILD.gn' ~/src/devtools/devtools-frontend/test/e2e/resources/lighthouse/ third-party/devtools-tests/e2e/resources/lighthouse/
14
+ ```
@@ -0,0 +1,29 @@
1
+ // Copyright 2020 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ import {assert} from 'chai';
6
+
7
+ import {goToResource} from '../../shared/helper.js';
8
+ import {describe, it} from '../../shared/mocha-extensions.js';
9
+ import {isGenerateReportButtonDisabled, navigateToLighthouseTab} from '../helpers/lighthouse-helpers.js';
10
+
11
+ describe('The Lighthouse Tab', function() {
12
+ this.timeout(20_000);
13
+
14
+ it('shows a button to generate a new report', async () => {
15
+ await navigateToLighthouseTab('empty.html');
16
+
17
+ const disabled = await isGenerateReportButtonDisabled();
18
+ assert.isFalse(disabled, 'The Generate Report button should not be disabled');
19
+ });
20
+
21
+ // Broken on non-debug runs
22
+ it.skip('[crbug.com/1057948] shows generate report button even when navigating to an unreachable page', async () => {
23
+ await navigateToLighthouseTab('empty.html');
24
+
25
+ await goToResource('network/unreachable.rawresponse');
26
+ const disabled = await isGenerateReportButtonDisabled();
27
+ assert.isTrue(disabled, 'The Generate Report button should be disabled');
28
+ });
29
+ });
@@ -0,0 +1,29 @@
1
+ // Copyright 2022 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ import {assert} from 'chai';
6
+
7
+ import {waitFor} from '../../shared/helper.js';
8
+ import {describe, it} from '../../shared/mocha-extensions.js';
9
+ import {navigateToLighthouseTab} from '../helpers/lighthouse-helpers.js';
10
+
11
+ describe('IndexedDB warning', function() {
12
+ this.timeout(20_000);
13
+
14
+ it('displays when important data may affect performance', async () => {
15
+ await navigateToLighthouseTab('empty.html');
16
+
17
+ let warningElem = await waitFor('.lighthouse-warning-text.hidden');
18
+ const warningText1 = await warningElem.evaluate(node => node.textContent?.trim());
19
+ assert.strictEqual(warningText1, '');
20
+
21
+ await navigateToLighthouseTab('lighthouse/lighthouse-storage.html');
22
+
23
+ warningElem = await waitFor('.lighthouse-warning-text:not(.hidden)');
24
+ const expected =
25
+ 'There may be stored data affecting loading performance in this location: IndexedDB. Audit this page in an incognito window to prevent those resources from affecting your scores.';
26
+ const warningText2 = await warningElem.evaluate(node => node.textContent?.trim());
27
+ assert.strictEqual(warningText2, expected);
28
+ });
29
+ });
@@ -0,0 +1,11 @@
1
+ <!DOCTYPE html>
2
+ <head>
3
+ <meta charset="UTF-8">
4
+ <script>
5
+ // Indexeddb
6
+ window.indexedDB.open("DataBase", 3);
7
+ </script>
8
+ </head>
9
+ <body>
10
+ hi
11
+ </body>
@@ -6,3 +6,4 @@ Some minor patches on top from the Lighthouse Authors:
6
6
 
7
7
  * deleting code we don't need
8
8
  * changing output path
9
+ * --resolve-executable-path
@@ -34,7 +34,6 @@ function main() {
34
34
  console.log('Unable to download because of error:', error);
35
35
  }
36
36
  }
37
- main();
38
37
 
39
38
  function onUploadedCommitPosition(commitPosition) {
40
39
  const contentShellDirPath = path.resolve(CACHE_PATH, commitPosition, 'out', TARGET);
@@ -176,3 +175,9 @@ function getContentShellBinaryPath(dirPath) {
176
175
  return path.resolve(dirPath, 'Content Shell.app', 'Contents', 'MacOS', 'Content Shell');
177
176
  }
178
177
  }
178
+
179
+ if (process.argv[2] === '--resolve-executable-path') {
180
+ console.log(getContentShellBinaryPath(process.argv[3]));
181
+ } else {
182
+ main();
183
+ }
@@ -28,8 +28,6 @@ declare module Gatherer {
28
28
  setNextProtocolTimeout(ms: number): void;
29
29
  on<TEvent extends keyof LH.CrdpEvents>(event: TEvent, callback: (...args: LH.CrdpEvents[TEvent]) => void): void;
30
30
  once<TEvent extends keyof LH.CrdpEvents>(event: TEvent, callback: (...args: LH.CrdpEvents[TEvent]) => void): void;
31
- addProtocolMessageListener(callback: (payload: Protocol.RawEventMessage) => void): void
32
- removeProtocolMessageListener(callback: (payload: Protocol.RawEventMessage) => void): void
33
31
  off<TEvent extends keyof LH.CrdpEvents>(event: TEvent, callback: (...args: LH.CrdpEvents[TEvent]) => void): void;
34
32
  sendCommand<TMethod extends keyof LH.CrdpCommands>(method: TMethod, ...params: LH.CrdpCommands[TMethod]['paramsType']): Promise<LH.CrdpCommands[TMethod]['returnType']>;
35
33
  dispose(): Promise<void>;
@@ -41,6 +39,11 @@ declare module Gatherer {
41
39
  executionContext: ExecutionContext;
42
40
  fetcher: Fetcher;
43
41
  url: () => Promise<string>;
42
+ targetManager: {
43
+ rootSession(): FRProtocolSession;
44
+ on(event: 'protocolevent', callback: (payload: Protocol.RawEventMessage) => void): void
45
+ off(event: 'protocolevent', callback: (payload: Protocol.RawEventMessage) => void): void
46
+ };
44
47
  }
45
48
 
46
49
  /** The limited context interface shared between pre and post Fraggle Rock Lighthouse. */
@@ -5,6 +5,23 @@
5
5
  */
6
6
 
7
7
  declare module Protocol {
8
+ /**
9
+ * An intermediate type, used to create a record of all possible Crdp raw event
10
+ * messages, keyed on method. e.g. {
11
+ * 'Domain.method1Name': {method: 'Domain.method1Name', params: EventPayload1},
12
+ * 'Domain.method2Name': {method: 'Domain.method2Name', params: EventPayload2},
13
+ * }
14
+ */
15
+ type RawEventMessageRecord = {
16
+ [K in keyof LH.CrdpEvents]: {
17
+ method: K,
18
+ // Drop [] for `undefined` (so a JS value is valid).
19
+ params: LH.CrdpEvents[K] extends [] ? undefined: LH.CrdpEvents[K][number]
20
+ // If sessionId is not set, it means the event was from the root target.
21
+ sessionId?: string;
22
+ };
23
+ }
24
+
8
25
  /**
9
26
  * Union of raw (over the wire) message format of all possible Crdp events,
10
27
  * of the form `{method: 'Domain.event', params: eventPayload}`.
@@ -36,7 +53,7 @@ declare module Protocol {
36
53
  * serve as the arguments to event listener callbacks.
37
54
  * Inspired by work from https://github.com/bterlson/strict-event-emitter-types.
38
55
  */
39
- type StrictEventEmitter<TEventRecord extends Record<keyof TEventRecord, any[]>> = {
56
+ type StrictEventEmitter<TEventRecord extends Record<keyof TEventRecord, unknown[]>> = {
40
57
  on<E extends keyof TEventRecord>(event: E, listener: (...args: TEventRecord[E]) => void): void;
41
58
 
42
59
  off<E extends keyof TEventRecord>(event: E, listener: Function): void;
@@ -50,24 +67,16 @@ declare module Protocol {
50
67
  once<E extends keyof TEventRecord>(event: E, listener: (...args: TEventRecord[E]) => void): void;
51
68
 
52
69
  emit<E extends keyof TEventRecord>(event: E, ...request: TEventRecord[E]): void;
70
+
71
+ listenerCount<E extends keyof TEventRecord>(event: E): number;
53
72
  }
54
- }
55
73
 
56
- /**
57
- * An intermediate type, used to create a record of all possible Crdp raw event
58
- * messages, keyed on method. e.g. {
59
- * 'Domain.method1Name': {method: 'Domain.method1Name', params: EventPayload1},
60
- * 'Domain.method2Name': {method: 'Domain.method2Name', params: EventPayload2},
61
- * }
62
- */
63
- type RawEventMessageRecord = {
64
- [K in keyof LH.CrdpEvents]: {
65
- method: K,
66
- // Drop [] for `undefined` (so a JS value is valid).
67
- params: LH.CrdpEvents[K] extends [] ? undefined: LH.CrdpEvents[K][number]
68
- // If sessionId is not set, it means the event was from the root target.
69
- sessionId?: string;
70
- };
74
+ /**
75
+ * A constructable StrictEventEmitter.
76
+ */
77
+ interface StrictEventEmitterClass<TEventRecord extends Record<keyof TEventRecord, unknown[]>> {
78
+ new(): StrictEventEmitter<TEventRecord>;
79
+ }
71
80
  }
72
81
 
73
82
  export default Protocol;