chrome-devtools-frontend 1.0.971727 → 1.0.973342

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 (46) hide show
  1. package/config/gni/devtools_grd_files.gni +2 -1
  2. package/front_end/core/i18n/locales/en-US.json +24 -0
  3. package/front_end/core/i18n/locales/en-XL.json +24 -0
  4. package/front_end/core/sdk/NetworkManager.ts +15 -7
  5. package/front_end/core/sdk/NetworkRequest.ts +16 -14
  6. package/front_end/core/sdk/ResourceTreeModel.ts +8 -10
  7. package/front_end/core/sdk/SourceMap.ts +9 -9
  8. package/front_end/entrypoints/lighthouse_worker/{LighthouseService.ts → LighthouseWorkerService.ts} +69 -38
  9. package/front_end/entrypoints/lighthouse_worker/lighthouse_worker.ts +1 -1
  10. package/front_end/models/bindings/CSSWorkspaceBinding.ts +2 -16
  11. package/front_end/models/bindings/SASSSourceMapping.ts +4 -3
  12. package/front_end/models/har/HARFormat.ts +4 -2
  13. package/front_end/models/har/Importer.ts +0 -1
  14. package/front_end/models/persistence/FileSystemWorkspaceBinding.ts +4 -4
  15. package/front_end/models/persistence/IsolatedFileSystem.ts +0 -1
  16. package/front_end/models/text_utils/StaticContentProvider.ts +5 -4
  17. package/front_end/models/workspace_diff/WorkspaceDiff.ts +20 -8
  18. package/front_end/panels/application/ServiceWorkerCacheViews.ts +2 -1
  19. package/front_end/panels/changes/ChangesView.ts +4 -4
  20. package/front_end/panels/elements/StylesSidebarPane.ts +27 -15
  21. package/front_end/panels/elements/components/LayoutPane.ts +1 -1
  22. package/front_end/panels/lighthouse/LighthouseController.ts +13 -2
  23. package/front_end/panels/lighthouse/LighthousePanel.ts +57 -8
  24. package/front_end/panels/lighthouse/LighthouseProtocolService.ts +94 -30
  25. package/front_end/panels/lighthouse/LighthouseStartView.ts +6 -2
  26. package/front_end/panels/lighthouse/LighthouseStartViewFR.ts +61 -0
  27. package/front_end/panels/lighthouse/LighthouseTimespanView.ts +99 -0
  28. package/front_end/panels/sources/NavigatorView.ts +4 -4
  29. package/front_end/third_party/codemirror.next/bundle.ts +1 -1
  30. package/front_end/third_party/codemirror.next/chunk/codemirror.js +1 -1
  31. package/front_end/third_party/codemirror.next/chunk/json.js +2 -1
  32. package/front_end/third_party/codemirror.next/codemirror.next.d.ts +28 -2
  33. package/front_end/third_party/codemirror.next/codemirror.next.js +1 -1
  34. package/front_end/third_party/codemirror.next/package.json +10 -10
  35. package/front_end/third_party/lighthouse/lighthouse-dt-bundle.js +1047 -1158
  36. package/front_end/third_party/lighthouse/locales/en-US.json +7 -1
  37. package/front_end/third_party/lighthouse/locales/en-XL.json +7 -1
  38. package/front_end/third_party/lighthouse/report/bundle.d.ts +0 -3
  39. package/front_end/third_party/lighthouse/report/bundle.js +38 -24
  40. package/front_end/third_party/lighthouse/report-assets/report-generator.mjs +1 -1
  41. package/front_end/ui/components/expandable_list/expandableList.css +1 -1
  42. package/front_end/ui/components/text_editor/config.ts +1 -0
  43. package/front_end/ui/legacy/components/source_frame/BinaryResourceViewFactory.ts +7 -4
  44. package/front_end/ui/legacy/tabbedPane.css +1 -0
  45. package/package.json +1 -1
  46. package/scripts/hosted_mode/server.js +13 -0
@@ -8,15 +8,58 @@ import * as SDK from '../../core/sdk/sdk.js';
8
8
 
9
9
  import type * as ReportRenderer from './LighthouseReporterTypes.js';
10
10
 
11
+ /**
12
+ * @overview
13
+ ┌────────────┐
14
+ │CDP Backend │
15
+ └────────────┘
16
+ │ ▲
17
+ │ │ parallelConnection
18
+ ┌┐ ▼ │ ┌┐
19
+ ││ dispatchProtocolMessage sendProtocolMessage ││
20
+ ││ │ ▲ ││
21
+ ProtocolService ││ | │ ││
22
+ ││ sendWithResponse ▼ │ ││
23
+ ││ │ send onWorkerMessage ││
24
+ └┘ │ │ ▲ └┘
25
+ worker boundary - - - - - - - - ┼ - -│- - - - - - - - -│- - - - - - - - - - - -
26
+ ┌┐ ▼ ▼ │ ┌┐
27
+ ││ onFrontendMessage notifyFrontendViaWorkerMessage ││
28
+ ││ │ ▲ ││
29
+ ││ ▼ │ ││
30
+ LighthouseWorkerService ││ Either ConnectionProxy or LegacyPort ││
31
+ ││ │ ▲ ││
32
+ ││ ┌─────────────────────┼─┼───────────────────────┐ ││
33
+ ││ │ Lighthouse ┌────▼──────┐ │ ││
34
+ ││ │ │connection │ │ ││
35
+ ││ │ └───────────┘ │ ││
36
+ └┘ └───────────────────────────────────────────────┘ └┘
37
+
38
+ * All messages traversing the worker boundary are action-wrapped.
39
+ * All messages over the parallelConnection speak pure CDP.
40
+ * All messages within ConnectionProxy/LegacyPort speak pure CDP.
41
+ * The foundational CDP connection is `parallelConnection`.
42
+ * All connections within the worker are not actual ParallelConnection's.
43
+ */
44
+
11
45
  let lastId = 1;
12
46
 
47
+ export interface LighthouseRun {
48
+ inspectedURL: string;
49
+ categoryIDs: string[];
50
+ flags: Record<string, Object|undefined>;
51
+ }
52
+
53
+ /**
54
+ * ProtocolService manages a connection between the frontend (Lighthouse panel) and the Lighthouse worker.
55
+ */
13
56
  export class ProtocolService {
14
57
  private targetInfo?: {
15
58
  mainSessionId: string,
16
59
  mainTargetId: string,
17
60
  mainFrameId: string,
18
61
  };
19
- private rawConnection?: ProtocolClient.InspectorBackend.Connection;
62
+ private parallelConnection?: ProtocolClient.InspectorBackend.Connection;
20
63
  private lighthouseWorkerPromise?: Promise<Worker>;
21
64
  private lighthouseMessageUpdateCallback?: ((arg0: string) => void);
22
65
 
@@ -46,7 +89,7 @@ export class ProtocolService {
46
89
  this.dispatchProtocolMessage(message);
47
90
  });
48
91
 
49
- this.rawConnection = connection;
92
+ this.parallelConnection = connection;
50
93
  this.targetInfo = {
51
94
  mainTargetId: await childTargetManager.getParentTargetId(),
52
95
  mainFrameId: mainFrame.id,
@@ -58,19 +101,36 @@ export class ProtocolService {
58
101
  return [i18n.DevToolsLocale.DevToolsLocale.instance().locale];
59
102
  }
60
103
 
61
- async startLighthouse(auditURL: string, categoryIDs: string[], flags: Record<string, Object|undefined>):
62
- Promise<ReportRenderer.RunnerResult> {
104
+ async startTimespan(currentLighthouseRun: LighthouseRun): Promise<void> {
105
+ const {inspectedURL, categoryIDs, flags} = currentLighthouseRun;
106
+
107
+ if (!this.targetInfo) {
108
+ throw new Error('Unable to get target info required for Lighthouse');
109
+ }
110
+
111
+ await this.sendWithResponse('startTimespan', {
112
+ url: inspectedURL,
113
+ categoryIDs,
114
+ flags,
115
+ locales: this.getLocales(),
116
+ target: this.targetInfo,
117
+ });
118
+ }
119
+
120
+ async collectLighthouseResults(currentLighthouseRun: LighthouseRun): Promise<ReportRenderer.RunnerResult> {
121
+ const {inspectedURL, categoryIDs, flags} = currentLighthouseRun;
122
+
63
123
  if (!this.targetInfo) {
64
124
  throw new Error('Unable to get target info required for Lighthouse');
65
125
  }
66
126
 
67
127
  let mode = flags.mode as string;
68
- if (mode === 'navigation' && flags.legacyNavigation) {
69
- mode = 'legacyNavigation';
128
+ if (mode === 'timespan') {
129
+ mode = 'endTimespan';
70
130
  }
71
131
 
72
132
  return this.sendWithResponse(mode, {
73
- url: auditURL,
133
+ url: inspectedURL,
74
134
  categoryIDs,
75
135
  flags,
76
136
  locales: this.getLocales(),
@@ -80,20 +140,20 @@ export class ProtocolService {
80
140
 
81
141
  async detach(): Promise<void> {
82
142
  const oldLighthouseWorker = this.lighthouseWorkerPromise;
83
- const oldRawConnection = this.rawConnection;
143
+ const oldParallelConnection = this.parallelConnection;
84
144
 
85
145
  // When detaching, make sure that we remove the old promises, before we
86
146
  // perform any async cleanups. That way, if there is a message coming from
87
147
  // lighthouse while we are in the process of cleaning up, we shouldn't deliver
88
148
  // them to the backend.
89
149
  this.lighthouseWorkerPromise = undefined;
90
- this.rawConnection = undefined;
150
+ this.parallelConnection = undefined;
91
151
 
92
152
  if (oldLighthouseWorker) {
93
153
  (await oldLighthouseWorker).terminate();
94
154
  }
95
- if (oldRawConnection) {
96
- await oldRawConnection.disconnect();
155
+ if (oldParallelConnection) {
156
+ await oldParallelConnection.disconnect();
97
157
  }
98
158
  await SDK.TargetManager.TargetManager.instance().resumeAllTargets();
99
159
  }
@@ -117,7 +177,7 @@ export class ProtocolService {
117
177
  method?: string,
118
178
  };
119
179
  if (protocolMessage.sessionId || (protocolMessage.method && protocolMessage.method.startsWith('Target'))) {
120
- void this.sendWithoutResponse('dispatchProtocolMessage', {message: JSON.stringify(message)});
180
+ void this.send('dispatchProtocolMessage', {message: JSON.stringify(message)});
121
181
  }
122
182
  }
123
183
 
@@ -137,18 +197,7 @@ export class ProtocolService {
137
197
  return;
138
198
  }
139
199
 
140
- const lighthouseMessage = JSON.parse(event.data);
141
-
142
- if (lighthouseMessage.method === 'statusUpdate') {
143
- if (this.lighthouseMessageUpdateCallback && lighthouseMessage.params &&
144
- 'message' in lighthouseMessage.params) {
145
- this.lighthouseMessageUpdateCallback(lighthouseMessage.params.message as string);
146
- }
147
- } else if (lighthouseMessage.method === 'sendProtocolMessage') {
148
- if (lighthouseMessage.params && 'message' in lighthouseMessage.params) {
149
- this.sendProtocolMessage(lighthouseMessage.params.message as string);
150
- }
151
- }
200
+ this.onWorkerMessage(event);
152
201
  });
153
202
  });
154
203
  return this.lighthouseWorkerPromise;
@@ -164,19 +213,34 @@ export class ProtocolService {
164
213
  return worker;
165
214
  }
166
215
 
216
+ private onWorkerMessage(event: MessageEvent): void {
217
+ const lighthouseMessage = JSON.parse(event.data);
218
+
219
+ if (lighthouseMessage.action === 'statusUpdate') {
220
+ if (this.lighthouseMessageUpdateCallback && lighthouseMessage.args && 'message' in lighthouseMessage.args) {
221
+ this.lighthouseMessageUpdateCallback(lighthouseMessage.args.message as string);
222
+ }
223
+ } else if (lighthouseMessage.action === 'sendProtocolMessage') {
224
+ if (lighthouseMessage.args && 'message' in lighthouseMessage.args) {
225
+ this.sendProtocolMessage(lighthouseMessage.args.message as string);
226
+ }
227
+ }
228
+ }
229
+
167
230
  private sendProtocolMessage(message: string): void {
168
- if (this.rawConnection) {
169
- this.rawConnection.sendRawMessage(message);
231
+ if (this.parallelConnection) {
232
+ this.parallelConnection.sendRawMessage(message);
170
233
  }
171
234
  }
172
235
 
173
- private async sendWithoutResponse(method: string, params: {[x: string]: string|string[]|Object} = {}): Promise<void> {
236
+ private async send(action: string, args: {[x: string]: string|string[]|Object} = {}): Promise<void> {
174
237
  const worker = await this.ensureWorkerExists();
175
238
  const messageId = lastId++;
176
- worker.postMessage(JSON.stringify({id: messageId, method, params: {...params, id: messageId}}));
239
+ worker.postMessage(JSON.stringify({id: messageId, action, args: {...args, id: messageId}}));
177
240
  }
178
241
 
179
- private async sendWithResponse(method: string, params: {[x: string]: string|string[]|Object} = {}):
242
+ /** sendWithResponse currently only handles the original startLighthouse request and LHR-filled response. */
243
+ private async sendWithResponse(action: string, args: {[x: string]: string|string[]|Object} = {}):
180
244
  Promise<ReportRenderer.RunnerResult> {
181
245
  const worker = await this.ensureWorkerExists();
182
246
  const messageId = lastId++;
@@ -191,7 +255,7 @@ export class ProtocolService {
191
255
  };
192
256
  worker.addEventListener('message', workerListener);
193
257
  });
194
- worker.postMessage(JSON.stringify({id: messageId, method, params: {...params, id: messageId}}));
258
+ worker.postMessage(JSON.stringify({id: messageId, action, args: {...args, id: messageId}}));
195
259
 
196
260
  return messageResult;
197
261
  }
@@ -41,9 +41,9 @@ const UIStrings = {
41
41
  const str_ = i18n.i18n.registerUIStrings('panels/lighthouse/LighthouseStartView.ts', UIStrings);
42
42
  const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
43
43
  export class StartView extends UI.Widget.Widget {
44
- private controller: LighthouseController;
44
+ protected controller: LighthouseController;
45
45
  private readonly settingsToolbarInternal: UI.Toolbar.Toolbar;
46
- private startButton!: HTMLButtonElement;
46
+ protected startButton!: HTMLButtonElement;
47
47
  private helpText?: Element;
48
48
  private warningText?: Element;
49
49
  private shouldConfirm?: boolean;
@@ -173,6 +173,10 @@ export class StartView extends UI.Widget.Widget {
173
173
  this.contentElement.style.overflow = 'auto';
174
174
  }
175
175
 
176
+ updateStartButton(): void {
177
+ // Do nothing in default case.
178
+ }
179
+
176
180
  onResize(): void {
177
181
  const useNarrowLayout = this.contentElement.offsetWidth < 560;
178
182
  const startViewEl = this.contentElement.querySelector('.lighthouse-start-view');
@@ -4,14 +4,28 @@
4
4
 
5
5
  import * as i18n from '../../core/i18n/i18n.js';
6
6
  import * as UI from '../../ui/legacy/legacy.js';
7
+ import type * as Platform from '../../core/platform/platform.js';
7
8
 
8
9
  import {StartView} from './LighthouseStartView.js';
10
+ import {Events} from './LighthouseController.js';
9
11
 
10
12
  const UIStrings = {
11
13
  /**
12
14
  * @description Text that refers to the Lighthouse mode
13
15
  */
14
16
  mode: 'Mode',
17
+ /**
18
+ * @description Label for a button to start analyzing a page navigation with Lighthouse
19
+ */
20
+ analyzeNavigation: 'Analyze navigation',
21
+ /**
22
+ * @description Label for a button to start analyzing the current page state with Lighthouse
23
+ */
24
+ analyzeSnapshot: 'Analyze snapshot',
25
+ /**
26
+ * @description Label for a button that ends a Lighthouse timespan
27
+ */
28
+ startTimespan: 'Start timespan',
15
29
  };
16
30
 
17
31
  const str_ = i18n.i18n.registerUIStrings('panels/lighthouse/LighthouseStartViewFR.ts', UIStrings);
@@ -35,5 +49,52 @@ export class StartViewFR extends StartView {
35
49
 
36
50
  const form = this.contentElement.querySelector('form');
37
51
  form?.appendChild(fragment.element());
52
+ this.updateStartButton();
53
+ }
54
+
55
+ updateStartButton(): void {
56
+ const {mode} = this.controller.getFlags();
57
+
58
+ let label: Platform.UIString.LocalizedString;
59
+ let callback: () => void;
60
+
61
+ if (mode === 'timespan') {
62
+ label = i18nString(UIStrings.startTimespan);
63
+ callback = (): void => {
64
+ this.controller.dispatchEventToListeners(
65
+ Events.RequestLighthouseTimespanStart,
66
+ /* keyboardInitiated */ this.startButton.matches(':focus-visible'),
67
+ );
68
+ };
69
+ } else if (mode === 'snapshot') {
70
+ label = i18nString(UIStrings.analyzeSnapshot);
71
+ callback = (): void => {
72
+ this.controller.dispatchEventToListeners(
73
+ Events.RequestLighthouseStart,
74
+ /* keyboardInitiated */ this.startButton.matches(':focus-visible'),
75
+ );
76
+ };
77
+ } else {
78
+ label = i18nString(UIStrings.analyzeNavigation);
79
+ callback = (): void => {
80
+ this.controller.dispatchEventToListeners(
81
+ Events.RequestLighthouseStart,
82
+ /* keyboardInitiated */ this.startButton.matches(':focus-visible'),
83
+ );
84
+ };
85
+ }
86
+
87
+ this.startButton = UI.UIUtils.createTextButton(
88
+ label,
89
+ callback,
90
+ /* className */ '',
91
+ /* primary */ true,
92
+ );
93
+
94
+ const startButtonContainer = this.contentElement.querySelector('.lighthouse-start-button-container');
95
+ if (startButtonContainer) {
96
+ startButtonContainer.textContent = '';
97
+ startButtonContainer.appendChild(this.startButton);
98
+ }
38
99
  }
39
100
  }
@@ -0,0 +1,99 @@
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 * as i18n from '../../core/i18n/i18n.js';
6
+ import * as UI from '../../ui/legacy/legacy.js';
7
+
8
+ import type {LighthouseController} from './LighthouseController.js';
9
+ import {Events} from './LighthouseController.js';
10
+ import lighthouseDialogStyles from './lighthouseDialog.css.js';
11
+
12
+ const UIStrings = {
13
+ /**
14
+ * @description Header indicating that a Lighthouse timespan is starting.
15
+ */
16
+ timespanStarting: 'Timespan starting…',
17
+ /**
18
+ * @description Header indicating that a Lighthouse timespan has started.
19
+ */
20
+ timespanStarted: 'Timespan started, interact with the page',
21
+ /**
22
+ * @description Label for a button that ends a Lighthouse timespan.
23
+ */
24
+ endTimespan: 'End timespan',
25
+ /**
26
+ * @description Label for a button that cancels a Lighthouse timespan.
27
+ */
28
+ cancel: 'Cancel',
29
+ };
30
+
31
+ const str_ = i18n.i18n.registerUIStrings('panels/lighthouse/LighthouseTimespanView.ts', UIStrings);
32
+ const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
33
+
34
+ export class TimespanView extends UI.Dialog.Dialog {
35
+ private controller: LighthouseController;
36
+ private statusHeader: Element|null;
37
+ private endButton: HTMLButtonElement|null;
38
+
39
+ constructor(controller: LighthouseController) {
40
+ super();
41
+ this.controller = controller;
42
+ this.statusHeader = null;
43
+ this.endButton = null;
44
+ this.setDimmed(true);
45
+ this.setCloseOnEscape(false);
46
+ this.setOutsideClickCallback(event => event.consume(true));
47
+ this.render();
48
+ }
49
+
50
+ show(dialogRenderElement: Element): void {
51
+ this.reset();
52
+ super.show(dialogRenderElement);
53
+ }
54
+
55
+ reset(): void {
56
+ if (this.statusHeader && this.endButton) {
57
+ this.statusHeader.textContent = i18nString(UIStrings.timespanStarting);
58
+ this.endButton.disabled = true;
59
+ }
60
+ }
61
+
62
+ ready(): void {
63
+ if (this.statusHeader && this.endButton) {
64
+ this.statusHeader.textContent = i18nString(UIStrings.timespanStarted);
65
+ this.endButton.disabled = false;
66
+ this.endButton.focus();
67
+ }
68
+ }
69
+
70
+ render(): void {
71
+ const dialogRoot = UI.Utils.createShadowRootWithCoreStyles(
72
+ this.contentElement, {cssFile: [lighthouseDialogStyles], delegatesFocus: undefined});
73
+
74
+ this.endButton = UI.UIUtils.createTextButton(i18nString(UIStrings.endTimespan), this.endTimespan.bind(this));
75
+ const cancelButton = UI.UIUtils.createTextButton(i18nString(UIStrings.cancel), this.cancel.bind(this));
76
+ const fragment = UI.Fragment.Fragment.build`
77
+ <div class="lighthouse-view vbox">
78
+ <h2 $="status-header"></h2>
79
+ ${this.endButton}
80
+ ${cancelButton}
81
+ </div>
82
+ `;
83
+
84
+ this.statusHeader = fragment.$('status-header');
85
+ dialogRoot.appendChild(fragment.element());
86
+
87
+ this.setSizeBehavior(UI.GlassPane.SizeBehavior.SetExactWidthMaxHeight);
88
+ this.setMaxContentSize(new UI.Geometry.Size(500, 400));
89
+ this.reset();
90
+ }
91
+
92
+ private endTimespan(): void {
93
+ this.controller.dispatchEventToListeners(Events.RequestLighthouseTimespanEnd, false);
94
+ }
95
+
96
+ private cancel(): void {
97
+ this.controller.dispatchEventToListeners(Events.RequestLighthouseCancel);
98
+ }
99
+ }
@@ -400,7 +400,9 @@ export class NavigatorView extends UI.Widget.VBox implements SDK.TargetManager.O
400
400
 
401
401
  const removedFrame = (event.data.frame as SDK.ResourceTreeModel.ResourceTreeFrame | null);
402
402
  const node = Array.from(this.uiSourceCodeNodes.get(uiSourceCode)).find(node => node.frame() === removedFrame);
403
- this.removeUISourceCodeNode((node as NavigatorUISourceCodeTreeNode));
403
+ if (node) {
404
+ this.removeUISourceCodeNode(node);
405
+ }
404
406
  }
405
407
 
406
408
  private acceptsUISourceCode(uiSourceCode: Workspace.UISourceCode.UISourceCode): boolean {
@@ -852,10 +854,8 @@ export class NavigatorView extends UI.Widget.VBox implements SDK.TargetManager.O
852
854
  }
853
855
 
854
856
  if (project.type() === Workspace.Workspace.projectTypes.FileSystem) {
855
- // TODO(crbug.com/1253323): Cast to RawPathString will be removed when migration to branded types is complete.
856
857
  const folderPath = Common.ParsedURL.ParsedURL.urlToRawPathString(
857
- Persistence.FileSystemWorkspaceBinding.FileSystemWorkspaceBinding.completeURL(project, path) as
858
- Platform.DevToolsPath.UrlString,
858
+ Persistence.FileSystemWorkspaceBinding.FileSystemWorkspaceBinding.completeURL(project, path),
859
859
  Host.Platform.isWin());
860
860
  contextMenu.revealSection().appendItem(
861
861
  i18nString(UIStrings.openFolder),
@@ -30,7 +30,7 @@ export {ensureSyntaxTree, indentOnInput, indentUnit,Language, LanguageSupport, s
30
30
  export {bracketMatching} from '@codemirror/matchbrackets';
31
31
  export {Panel, showPanel} from '@codemirror/panel';
32
32
  export {Range, RangeSet, RangeSetBuilder} from '@codemirror/rangeset';
33
- export {selectNextOccurrence} from '@codemirror/search';
33
+ export { highlightSelectionMatches,selectNextOccurrence} from '@codemirror/search';
34
34
  export {
35
35
  Annotation, AnnotationType, ChangeDesc, ChangeSet, ChangeSpec, Compartment,
36
36
  EditorSelection, EditorState, EditorStateConfig, Extension, Facet, MapMode