chrome-devtools-frontend 1.0.972361 → 1.0.973446

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 (34) 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 -36
  9. package/front_end/entrypoints/lighthouse_worker/lighthouse_worker.ts +1 -1
  10. package/front_end/models/bindings/SASSSourceMapping.ts +4 -3
  11. package/front_end/models/har/HARFormat.ts +4 -2
  12. package/front_end/models/har/Importer.ts +0 -1
  13. package/front_end/models/persistence/FileSystemWorkspaceBinding.ts +4 -4
  14. package/front_end/models/persistence/IsolatedFileSystem.ts +0 -1
  15. package/front_end/models/text_utils/StaticContentProvider.ts +5 -4
  16. package/front_end/panels/application/ServiceWorkerCacheViews.ts +2 -1
  17. package/front_end/panels/elements/components/LayoutPane.ts +1 -1
  18. package/front_end/panels/lighthouse/LighthouseController.ts +13 -2
  19. package/front_end/panels/lighthouse/LighthousePanel.ts +57 -8
  20. package/front_end/panels/lighthouse/LighthouseProtocolService.ts +94 -30
  21. package/front_end/panels/lighthouse/LighthouseStartView.ts +6 -2
  22. package/front_end/panels/lighthouse/LighthouseStartViewFR.ts +61 -0
  23. package/front_end/panels/lighthouse/LighthouseTimespanView.ts +99 -0
  24. package/front_end/panels/sources/NavigatorView.ts +1 -3
  25. package/front_end/third_party/codemirror.next/bundle.ts +1 -1
  26. package/front_end/third_party/codemirror.next/chunk/codemirror.js +1 -1
  27. package/front_end/third_party/codemirror.next/chunk/json.js +2 -1
  28. package/front_end/third_party/codemirror.next/codemirror.next.d.ts +28 -2
  29. package/front_end/third_party/codemirror.next/codemirror.next.js +1 -1
  30. package/front_end/third_party/codemirror.next/package.json +10 -10
  31. package/front_end/ui/components/expandable_list/expandableList.css +1 -1
  32. package/front_end/ui/components/text_editor/config.ts +1 -0
  33. package/front_end/ui/legacy/components/source_frame/BinaryResourceViewFactory.ts +7 -4
  34. package/package.json +1 -1
@@ -79,9 +79,9 @@ export class FileSystemWorkspaceBinding {
79
79
  return fileSystem.supportsAutomapping();
80
80
  }
81
81
 
82
- static completeURL(project: Workspace.Workspace.Project, relativePath: string): string {
82
+ static completeURL(project: Workspace.Workspace.Project, relativePath: string): Platform.DevToolsPath.UrlString {
83
83
  const fsProject = project as FileSystem;
84
- return fsProject.fileSystemBaseURL + relativePath;
84
+ return Common.ParsedURL.ParsedURL.concatenate(fsProject.fileSystemBaseURL, relativePath);
85
85
  }
86
86
 
87
87
  static fileSystemPath(projectId: string): string {
@@ -155,7 +155,7 @@ export class FileSystemWorkspaceBinding {
155
155
 
156
156
  export class FileSystem extends Workspace.Workspace.ProjectStore {
157
157
  readonly fileSystemInternal: PlatformFileSystem;
158
- readonly fileSystemBaseURL: string;
158
+ readonly fileSystemBaseURL: Platform.DevToolsPath.UrlString;
159
159
  private readonly fileSystemParentURL: string;
160
160
  private readonly fileSystemWorkspaceBinding: FileSystemWorkspaceBinding;
161
161
  private readonly fileSystemPathInternal: string;
@@ -171,7 +171,7 @@ export class FileSystem extends Workspace.Workspace.ProjectStore {
171
171
  super(workspace, id, Workspace.Workspace.projectTypes.FileSystem, displayName);
172
172
 
173
173
  this.fileSystemInternal = isolatedFileSystem;
174
- this.fileSystemBaseURL = this.fileSystemInternal.path() + '/';
174
+ this.fileSystemBaseURL = Common.ParsedURL.ParsedURL.concatenate(this.fileSystemInternal.path(), '/');
175
175
  this.fileSystemParentURL = this.fileSystemBaseURL.substr(0, fileSystemPath.lastIndexOf('/') + 1);
176
176
  this.fileSystemWorkspaceBinding = fileSystemWorkspaceBinding;
177
177
  this.fileSystemPathInternal = fileSystemPath;
@@ -81,7 +81,6 @@ export class IsolatedFileSystem extends PlatformFileSystem {
81
81
 
82
82
  constructor(
83
83
  manager: IsolatedFileSystemManager, path: string, embedderPath: string, domFileSystem: FileSystem, type: string) {
84
- // TODO(crbug.com/1253323): Cast to UrlString will be removed when migration to branded types is complete.
85
84
  super(path, type);
86
85
  this.manager = manager;
87
86
  this.embedderPathInternal = embedderPath;
@@ -14,9 +14,9 @@ export class StaticContentProvider implements ContentProvider {
14
14
  private readonly lazyContent: () => Promise<DeferredContent>;
15
15
 
16
16
  constructor(
17
- contentURL: string, contentType: Common.ResourceType.ResourceType, lazyContent: () => Promise<DeferredContent>) {
18
- // TODO(crbug.com/1253323): Cast to UrlString will be removed when migration to branded types is complete.
19
- this.contentURLInternal = contentURL as Platform.DevToolsPath.UrlString;
17
+ contentURL: Platform.DevToolsPath.UrlString, contentType: Common.ResourceType.ResourceType,
18
+ lazyContent: () => Promise<DeferredContent>) {
19
+ this.contentURLInternal = contentURL;
20
20
  this.contentTypeInternal = contentType;
21
21
  this.lazyContent = lazyContent;
22
22
  }
@@ -27,7 +27,8 @@ export class StaticContentProvider implements ContentProvider {
27
27
  content: string,
28
28
  isEncoded: boolean,
29
29
  }> => Promise.resolve({content, isEncoded: false});
30
- return new StaticContentProvider(contentURL, contentType, lazyContent);
30
+ // TODO(crbug.com/1253323): Cast to UrlString will be removed when migration to branded types is complete.
31
+ return new StaticContentProvider(contentURL as Platform.DevToolsPath.UrlString, contentType, lazyContent);
31
32
  }
32
33
 
33
34
  contentURL(): Platform.DevToolsPath.UrlString {
@@ -381,7 +381,8 @@ export class ServiceWorkerCacheView extends UI.View.SimpleView {
381
381
 
382
382
  private createRequest(entry: Protocol.CacheStorage.DataEntry): SDK.NetworkRequest.NetworkRequest {
383
383
  const request = SDK.NetworkRequest.NetworkRequest.createWithoutBackendRequest(
384
- 'cache-storage-' + entry.requestURL, entry.requestURL, '', null);
384
+ 'cache-storage-' + entry.requestURL, entry.requestURL as Platform.DevToolsPath.UrlString,
385
+ '' as Platform.DevToolsPath.UrlString, null);
385
386
  request.requestMethod = entry.requestMethod;
386
387
  request.setRequestHeaders(entry.requestHeaders);
387
388
  request.statusCode = entry.responseStatus;
@@ -270,7 +270,7 @@ export class LayoutPane extends HTMLElement {
270
270
  </span>
271
271
  </label>
272
272
  <label @keyup=${onColorLabelKeyUp} @keydown=${onColorLabelKeyDown} tabindex="0" title=${i18nString(UIStrings.chooseElementOverlayColor)} class="color-picker-label" style="background: ${element.color};">
273
- <input @change=${onColorChange} @input=${onColorChange} class="color-picker" type="color" value=${element.color} />
273
+ <input @change=${onColorChange} @input=${onColorChange} tabindex="-1" class="color-picker" type="color" value=${element.color} />
274
274
  </label>
275
275
  <button tabindex="0" @click=${onElementClick} title=${i18nString(UIStrings.showElementInTheElementsPanel)} class="show-element"></button>
276
276
  </div>`;
@@ -113,11 +113,15 @@ const UIStrings = {
113
113
  */
114
114
  runLighthouseInMode: 'Run Lighthouse in navigation, timespan, or snapshot mode',
115
115
  /**
116
- * @description Text for Lighthouse navigation mode.
116
+ * @description Label of a radio option for a Lighthouse mode that audits a page navigation.
117
117
  */
118
118
  navigation: 'Navigation',
119
119
  /**
120
- * @description Text for Lighthouse snapshot mode.
120
+ * @description Label of a radio option for a Lighthouse mode that audits user interactions over a period of time.
121
+ */
122
+ timespan: 'Timespan',
123
+ /**
124
+ * @description Label of a radio option for a Lighthouse mode that audits the current page state.
121
125
  */
122
126
  snapshot: 'Snapshot',
123
127
  /**
@@ -305,6 +309,7 @@ export class LighthouseController extends Common.ObjectWrapper.ObjectWrapper<Eve
305
309
  internalDisableDeviceScreenEmulation: boolean,
306
310
  emulatedFormFactor: (string|undefined),
307
311
  legacyNavigation: boolean,
312
+ mode: string,
308
313
  } {
309
314
  const flags = {
310
315
  // DevTools handles all the emulation. This tells Lighthouse to not bother with emulation.
@@ -317,6 +322,7 @@ export class LighthouseController extends Common.ObjectWrapper.ObjectWrapper<Eve
317
322
  internalDisableDeviceScreenEmulation: boolean,
318
323
  emulatedFormFactor: (string | undefined),
319
324
  legacyNavigation: boolean,
325
+ mode: string,
320
326
  };
321
327
  }
322
328
 
@@ -447,6 +453,7 @@ export const RuntimeSettings: RuntimeSetting[] = [
447
453
  },
448
454
  options: [
449
455
  {label: i18nLazyString(UIStrings.navigation), value: 'navigation'},
456
+ {label: i18nLazyString(UIStrings.timespan), value: 'timespan'},
450
457
  {label: i18nLazyString(UIStrings.snapshot), value: 'snapshot'},
451
458
  ],
452
459
  learnMore: undefined,
@@ -495,6 +502,8 @@ export enum Events {
495
502
  PageAuditabilityChanged = 'PageAuditabilityChanged',
496
503
  PageWarningsChanged = 'PageWarningsChanged',
497
504
  AuditProgressChanged = 'AuditProgressChanged',
505
+ RequestLighthouseTimespanStart = 'RequestLighthouseTimespanStart',
506
+ RequestLighthouseTimespanEnd = 'RequestLighthouseTimespanEnd',
498
507
  RequestLighthouseStart = 'RequestLighthouseStart',
499
508
  RequestLighthouseCancel = 'RequestLighthouseCancel',
500
509
  }
@@ -515,6 +524,8 @@ export type EventTypes = {
515
524
  [Events.PageAuditabilityChanged]: PageAuditabilityChangedEvent,
516
525
  [Events.PageWarningsChanged]: PageWarningsChangedEvent,
517
526
  [Events.AuditProgressChanged]: AuditProgressChangedEvent,
527
+ [Events.RequestLighthouseTimespanStart]: boolean,
528
+ [Events.RequestLighthouseTimespanEnd]: boolean,
518
529
  [Events.RequestLighthouseStart]: boolean,
519
530
  [Events.RequestLighthouseCancel]: void,
520
531
  };
@@ -14,6 +14,7 @@ import * as Emulation from '../emulation/emulation.js';
14
14
  import type {AuditProgressChangedEvent, PageAuditabilityChangedEvent, PageWarningsChangedEvent} from './LighthouseController.js';
15
15
  import {Events, LighthouseController} from './LighthouseController.js';
16
16
  import lighthousePanelStyles from './lighthousePanel.css.js';
17
+ import type {LighthouseRun} from './LighthouseProtocolService.js';
17
18
  import {ProtocolService} from './LighthouseProtocolService.js';
18
19
 
19
20
  import type {ReportJSON, RunnerResultArtifacts} from './LighthouseReporterTypes.js';
@@ -23,6 +24,7 @@ import {Item, ReportSelector} from './LighthouseReportSelector.js';
23
24
  import {StartView} from './LighthouseStartView.js';
24
25
  import {StartViewFR} from './LighthouseStartViewFR.js';
25
26
  import {StatusView} from './LighthouseStatusView.js';
27
+ import {TimespanView} from './LighthouseTimespanView.js';
26
28
 
27
29
  const UIStrings = {
28
30
  /**
@@ -65,6 +67,7 @@ export class LighthousePanel extends UI.Panel.Panel {
65
67
  private readonly controller: LighthouseController;
66
68
  private readonly startView: StartView;
67
69
  private readonly statusView: StatusView;
70
+ private readonly timespanView: TimespanView|null;
68
71
  private warningText: Nullable<string>;
69
72
  private unauditableExplanation: Nullable<string>;
70
73
  private readonly cachedRenderedReports: Map<ReportJSON, HTMLElement>;
@@ -81,6 +84,7 @@ export class LighthousePanel extends UI.Panel.Panel {
81
84
  network: {conditions: SDK.NetworkManager.Conditions},
82
85
  };
83
86
  private isLHAttached?: boolean;
87
+ private currentLighthouseRun?: LighthouseRun;
84
88
 
85
89
  private constructor() {
86
90
  super('lighthouse');
@@ -89,8 +93,10 @@ export class LighthousePanel extends UI.Panel.Panel {
89
93
  this.controller = new LighthouseController(this.protocolService);
90
94
  if (Root.Runtime.experiments.isEnabled('lighthousePanelFR')) {
91
95
  this.startView = new StartViewFR(this.controller);
96
+ this.timespanView = new TimespanView(this.controller);
92
97
  } else {
93
98
  this.startView = new StartView(this.controller);
99
+ this.timespanView = null;
94
100
  }
95
101
  this.statusView = new StatusView(this.controller);
96
102
 
@@ -105,12 +111,10 @@ export class LighthousePanel extends UI.Panel.Panel {
105
111
  this.controller.addEventListener(Events.PageAuditabilityChanged, this.refreshStartAuditUI.bind(this));
106
112
  this.controller.addEventListener(Events.PageWarningsChanged, this.refreshWarningsUI.bind(this));
107
113
  this.controller.addEventListener(Events.AuditProgressChanged, this.refreshStatusUI.bind(this));
108
- this.controller.addEventListener(Events.RequestLighthouseStart, _event => {
109
- void this.startLighthouse();
110
- });
111
- this.controller.addEventListener(Events.RequestLighthouseCancel, _event => {
112
- void this.cancelLighthouse();
113
- });
114
+ this.controller.addEventListener(Events.RequestLighthouseTimespanStart, this.onLighthouseTimespanStart.bind(this));
115
+ this.controller.addEventListener(Events.RequestLighthouseTimespanEnd, this.onLighthouseTimespanEnd.bind(this));
116
+ this.controller.addEventListener(Events.RequestLighthouseStart, this.onLighthouseStart.bind(this));
117
+ this.controller.addEventListener(Events.RequestLighthouseCancel, this.onLighthouseCancel.bind(this));
114
118
 
115
119
  this.renderToolbar();
116
120
  this.auditResultsElement = this.contentElement.createChild('div', 'lighthouse-results-container');
@@ -132,6 +136,27 @@ export class LighthousePanel extends UI.Panel.Panel {
132
136
  return Events;
133
137
  }
134
138
 
139
+ private async onLighthouseTimespanStart(): Promise<void> {
140
+ this.timespanView?.show(this.contentElement);
141
+ await this.startLighthouse();
142
+ this.timespanView?.ready();
143
+ }
144
+
145
+ private async onLighthouseTimespanEnd(): Promise<void> {
146
+ this.timespanView?.hide();
147
+ await this.collectLighthouseResults();
148
+ }
149
+
150
+ private async onLighthouseStart(): Promise<void> {
151
+ await this.startLighthouse();
152
+ await this.collectLighthouseResults();
153
+ }
154
+
155
+ private async onLighthouseCancel(): Promise<void> {
156
+ this.timespanView?.hide();
157
+ void this.cancelLighthouse();
158
+ }
159
+
135
160
  private refreshWarningsUI(evt: Common.EventTarget.EventTargetEvent<PageWarningsChangedEvent>): void {
136
161
  // PageWarningsChanged fires multiple times during an audit, which we want to ignore.
137
162
  if (this.isLHAttached) {
@@ -148,6 +173,8 @@ export class LighthousePanel extends UI.Panel.Panel {
148
173
  return;
149
174
  }
150
175
 
176
+ this.startView.updateStartButton();
177
+
151
178
  this.unauditableExplanation = evt.data.helpText;
152
179
  this.startView.setUnauditableExplanation(evt.data.helpText);
153
180
  this.startView.setStartButtonEnabled(!evt.data.helpText);
@@ -348,11 +375,30 @@ export class LighthousePanel extends UI.Panel.Panel {
348
375
  const categoryIDs = this.controller.getCategoryIDs();
349
376
  const flags = this.controller.getFlags();
350
377
 
378
+ this.currentLighthouseRun = {inspectedURL, categoryIDs, flags};
379
+
351
380
  await this.setupEmulationAndProtocolConnection();
352
381
 
353
- this.renderStatusView(inspectedURL);
382
+ if (flags.mode === 'timespan') {
383
+ await this.protocolService.startTimespan(this.currentLighthouseRun);
384
+ }
385
+
386
+ } catch (err) {
387
+ await this.resetEmulationAndProtocolConnection();
388
+ if (err instanceof Error) {
389
+ this.statusView.renderBugReport(err);
390
+ }
391
+ }
392
+ }
393
+
394
+ private async collectLighthouseResults(): Promise<void> {
395
+ try {
396
+ if (!this.currentLighthouseRun) {
397
+ throw new Error('Lighthouse is not started');
398
+ }
399
+ this.renderStatusView(this.currentLighthouseRun.inspectedURL);
354
400
 
355
- const lighthouseResponse = await this.protocolService.startLighthouse(inspectedURL, categoryIDs, flags);
401
+ const lighthouseResponse = await this.protocolService.collectLighthouseResults(this.currentLighthouseRun);
356
402
 
357
403
  if (lighthouseResponse && lighthouseResponse.fatal) {
358
404
  const error = new Error(lighthouseResponse.message);
@@ -375,10 +421,13 @@ export class LighthousePanel extends UI.Panel.Panel {
375
421
  if (err instanceof Error) {
376
422
  this.statusView.renderBugReport(err);
377
423
  }
424
+ } finally {
425
+ this.currentLighthouseRun = undefined;
378
426
  }
379
427
  }
380
428
 
381
429
  private async cancelLighthouse(): Promise<void> {
430
+ this.currentLighthouseRun = undefined;
382
431
  this.statusView.updateStatus(i18nString(UIStrings.cancelling));
383
432
  await this.resetEmulationAndProtocolConnection();
384
433
  this.renderStartView();
@@ -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
  }