chrome-devtools-frontend 1.0.1567721 → 1.0.1568190

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.
@@ -6,6 +6,7 @@ import * as Common from '../../../core/common/common.js';
6
6
  import * as i18n from '../../../core/i18n/i18n.js';
7
7
  import * as Platform from '../../../core/platform/platform.js';
8
8
  import * as Protocol from '../../../generated/protocol.js';
9
+ import * as Extras from '../extras/extras.js';
9
10
  import type * as Handlers from '../handlers/handlers.js';
10
11
  import * as Helpers from '../helpers/helpers.js';
11
12
  import type * as Lantern from '../lantern/lantern.js';
@@ -549,10 +550,8 @@ function candidateRequestsByOrigin(
549
550
  return;
550
551
  }
551
552
 
552
- // Filter out all resources that are loaded by the document. Connections are already early.
553
- // TODO(jacktfranklin, b/392090449): swap this over to use the initiator
554
- // lookup that fixes bugs with dynamically injected content.
555
- if (data.NetworkRequests.incompleteInitiator.get(request) === mainResource) {
553
+ const initiator = Extras.Initiators.getNetworkInitiator(data, request);
554
+ if (initiator === mainResource) {
556
555
  return;
557
556
  }
558
557
 
@@ -16,17 +16,15 @@ import * as Protocol from '../../../../generated/protocol.js';
16
16
  import * as LegacyWrapper from '../../../../ui/components/legacy_wrapper/legacy_wrapper.js';
17
17
  import * as RenderCoordinator from '../../../../ui/components/render_coordinator/render_coordinator.js';
18
18
  import * as UI from '../../../../ui/legacy/legacy.js';
19
- import * as Lit from '../../../../ui/lit/lit.js';
19
+ import {html, type LitTemplate, nothing, render} from '../../../../ui/lit/lit.js';
20
20
  import * as VisualLogging from '../../../../ui/visual_logging/visual_logging.js';
21
21
  import * as PreloadingHelper from '../helper/helper.js';
22
22
 
23
- import * as MismatchedPreloadingGrid from './MismatchedPreloadingGrid.js';
23
+ import {MismatchedPreloadingGrid, type MismatchedPreloadingGridData} from './MismatchedPreloadingGrid.js';
24
24
  import preloadingGridStyles from './preloadingGrid.css.js';
25
25
  import {prefetchFailureReason, prerenderFailureReason} from './PreloadingString.js';
26
26
  import usedPreloadingStyles from './usedPreloadingView.css.js';
27
27
 
28
- const {html} = Lit;
29
-
30
28
  const UIStrings = {
31
29
  /**
32
30
  * @description Header for preloading status.
@@ -139,6 +137,8 @@ const UIStrings = {
139
137
  const str_ = i18n.i18n.registerUIStrings('panels/application/preloading/components/UsedPreloadingView.ts', UIStrings);
140
138
  const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
141
139
 
140
+ const {widgetConfig} = UI.Widget;
141
+
142
142
  export interface UsedPreloadingViewData {
143
143
  pageURL: Platform.DevToolsPath.UrlString;
144
144
  previousAttempts: SDK.PreloadingModel.PreloadingAttempt[];
@@ -154,12 +154,292 @@ export const enum UsedKind {
154
154
  NO_PRELOADS = 'NoPreloads',
155
155
  }
156
156
 
157
+ type Badge = {
158
+ type: 'success',
159
+ count?: number,
160
+ }|{
161
+ type: 'failure',
162
+ count?: number,
163
+ }|{
164
+ type: 'neutral',
165
+ message: string,
166
+ };
167
+
168
+ interface MismatchedData {
169
+ pageURL: Platform.DevToolsPath.UrlString;
170
+ rows: MismatchedPreloadingGridData['rows'];
171
+ }
172
+
173
+ type AttemptWithMismatchedHeaders =
174
+ SDK.PreloadingModel.PrerenderAttempt|SDK.PreloadingModel.PrerenderUntilScriptAttempt;
175
+
176
+ interface SpeculativeLoadingStatusForThisPageData {
177
+ kind: UsedKind;
178
+ prefetch: SDK.PreloadingModel.PreloadingAttempt|undefined;
179
+ prerenderLike: SDK.PreloadingModel.PreloadingAttempt|undefined;
180
+ mismatchedData: MismatchedData|undefined;
181
+ attemptWithMismatchedHeaders: AttemptWithMismatchedHeaders|undefined;
182
+ }
183
+
184
+ function renderSpeculativeLoadingStatusForThisPageSections(
185
+ {kind, prefetch, prerenderLike, mismatchedData, attemptWithMismatchedHeaders}:
186
+ SpeculativeLoadingStatusForThisPageData): LitTemplate {
187
+ let badge: Badge;
188
+ let basicMessage: LitTemplate;
189
+ switch (kind) {
190
+ case UsedKind.DOWNGRADED_PRERENDER_TO_PREFETCH_AND_USED:
191
+ badge = {type: 'success'};
192
+ basicMessage = html`${i18nString(UIStrings.downgradedPrefetchUsed)}`;
193
+ break;
194
+ case UsedKind.PREFETCH_USED:
195
+ badge = {type: 'success'};
196
+ basicMessage = html`${i18nString(UIStrings.prefetchUsed)}`;
197
+ break;
198
+ case UsedKind.PRERENDER_USED:
199
+ badge = {type: 'success'};
200
+ basicMessage = html`${i18nString(UIStrings.prerenderUsed)}`;
201
+ break;
202
+ case UsedKind.PREFETCH_FAILED:
203
+ badge = {type: 'failure'};
204
+ basicMessage = html`${i18nString(UIStrings.prefetchFailed)}`;
205
+ break;
206
+ case UsedKind.PRERENDER_FAILED:
207
+ badge = {type: 'failure'};
208
+ basicMessage = html`${i18nString(UIStrings.prerenderFailed)}`;
209
+ break;
210
+ case UsedKind.NO_PRELOADS:
211
+ badge = {type: 'neutral', message: i18nString(UIStrings.badgeNoSpeculativeLoads)};
212
+ basicMessage = html`${i18nString(UIStrings.noPreloads)}`;
213
+ break;
214
+ }
215
+
216
+ let maybeFailureReasonMessage;
217
+ if (kind === UsedKind.PREFETCH_FAILED) {
218
+ assertNotNullOrUndefined(prefetch);
219
+ maybeFailureReasonMessage = prefetchFailureReason(prefetch as SDK.PreloadingModel.PrefetchAttempt);
220
+ } else if (kind === UsedKind.PRERENDER_FAILED || kind === UsedKind.DOWNGRADED_PRERENDER_TO_PREFETCH_AND_USED) {
221
+ assertNotNullOrUndefined(prerenderLike);
222
+ maybeFailureReasonMessage = prerenderFailureReason(
223
+ prerenderLike as SDK.PreloadingModel.PrerenderAttempt | SDK.PreloadingModel.PrerenderUntilScriptAttempt);
224
+ }
225
+
226
+ // Disabled until https://crbug.com/1079231 is fixed.
227
+ // clang-format off
228
+ return html`
229
+ <devtools-report-section-header>
230
+ ${i18nString(UIStrings.speculativeLoadingStatusForThisPage)}
231
+ </devtools-report-section-header>
232
+ <devtools-report-section>
233
+ <div>
234
+ <div class="status-badge-container">
235
+ ${renderBadge(badge)}
236
+ </div>
237
+ <div>
238
+ ${basicMessage}
239
+ </div>
240
+ </div>
241
+ </devtools-report-section>
242
+
243
+ ${maybeFailureReasonMessage !== undefined ? html`
244
+ <devtools-report-section-header>
245
+ ${i18nString(UIStrings.detailsFailureReason)}
246
+ </devtools-report-section-header>
247
+ <devtools-report-section>
248
+ ${maybeFailureReasonMessage}
249
+ </devtools-report-section>` : nothing}
250
+
251
+ ${mismatchedData ? renderMismatchedSections(mismatchedData) : nothing}
252
+ ${attemptWithMismatchedHeaders ?
253
+ renderMismatchedHTTPHeadersSections(attemptWithMismatchedHeaders) : nothing}`;
254
+ // clang-format on
255
+ }
256
+
257
+ function renderMismatchedSections(data: MismatchedData): LitTemplate {
258
+ // Disabled until https://crbug.com/1079231 is fixed.
259
+ // clang-format off
260
+ return html`
261
+ <devtools-report-section-header>
262
+ ${i18nString(UIStrings.currentURL)}
263
+ </devtools-report-section-header>
264
+ <devtools-report-section>
265
+ <x-link
266
+ class="link devtools-link"
267
+ href=${data.pageURL}
268
+ jslog=${VisualLogging.link()
269
+ .track({ click: true, keydown: 'Enter|Space' })
270
+ .context('current-url')}
271
+ >${data.pageURL}</x-link>
272
+ </devtools-report-section>
273
+
274
+ <devtools-report-section-header>
275
+ ${i18nString(UIStrings.preloadedURLs)}
276
+ </devtools-report-section-header>
277
+ <devtools-report-section jslog=${VisualLogging.section('preloaded-urls')}>
278
+ <devtools-widget .widgetConfig=${widgetConfig(MismatchedPreloadingGrid, {data})}>
279
+ </devtools-widget>
280
+ </devtools-report-section>`;
281
+ // clang-format on
282
+ }
283
+
284
+ function renderMismatchedHTTPHeadersSections(attempt: AttemptWithMismatchedHeaders): LitTemplate {
285
+ // Disabled until https://crbug.com/1079231 is fixed.
286
+ // clang-format off
287
+ return html`
288
+ <devtools-report-section-header>
289
+ ${i18nString(UIStrings.mismatchedHeadersDetail)}
290
+ </devtools-report-section-header>
291
+ <devtools-report-section>
292
+ <style>${preloadingGridStyles}</style>
293
+ <div class="preloading-container">
294
+ <devtools-data-grid striped inline>
295
+ <table>
296
+ <tr>
297
+ <th id="header-name" weight="30" sortable>
298
+ ${i18nString(UIStrings.headerName)}
299
+ </th>
300
+ <th id="initial-value" weight="30" sortable>
301
+ ${i18nString(UIStrings.initialNavigationValue)}
302
+ </th>
303
+ <th id="activation-value" weight="30" sortable>
304
+ ${i18nString(UIStrings.activationNavigationValue)}
305
+ </th>
306
+ </tr>
307
+ ${(attempt.mismatchedHeaders ?? []).map(mismatchedHeaders => html`
308
+ <tr>
309
+ <td>${mismatchedHeaders.headerName}</td>
310
+ <td>${mismatchedHeaders.initialValue ?? i18nString(UIStrings.missing)}</td>
311
+ <td>${mismatchedHeaders.activationValue ?? i18nString(UIStrings.missing)}</td>
312
+ </tr>
313
+ `)}
314
+ </table>
315
+ </devtools-data-grid>
316
+ </div>
317
+ </devtools-report-section>`;
318
+ // clang-format on
319
+ }
320
+
321
+ interface SpeculationsInitiatedByThisPageSummaryData {
322
+ badges: Badge[];
323
+ revealRuleSetView: () => void;
324
+ revealAttemptViewWithFilter: () => void;
325
+ }
326
+
327
+ interface ViewInput {
328
+ speculativeLoadingStatusData: SpeculativeLoadingStatusForThisPageData;
329
+ speculationsInitiatedSummaryData: SpeculationsInitiatedByThisPageSummaryData;
330
+ }
331
+
332
+ function renderSpeculationsInitiatedByThisPageSummarySections(
333
+ {badges, revealRuleSetView, revealAttemptViewWithFilter}: SpeculationsInitiatedByThisPageSummaryData): LitTemplate {
334
+ // Disabled until https://crbug.com/1079231 is fixed.
335
+ // clang-format off
336
+ return html`
337
+ <devtools-report-section-header>
338
+ ${i18nString(UIStrings.speculationsInitiatedByThisPage)}
339
+ </devtools-report-section-header>
340
+ <devtools-report-section>
341
+ <div>
342
+ <div class="status-badge-container">
343
+ ${badges.map(renderBadge)}
344
+ </div>
345
+
346
+ <div class="reveal-links">
347
+ <button class="link devtools-link" @click=${revealRuleSetView}
348
+ jslog=${VisualLogging.action('view-all-rules').track({click: true})}>
349
+ ${i18nString(UIStrings.viewAllRules)}
350
+ </button>
351
+
352
+ <button class="link devtools-link" @click=${revealAttemptViewWithFilter}
353
+ jslog=${VisualLogging.action('view-all-speculations').track({click: true})}>
354
+ ${i18nString(UIStrings.viewAllSpeculations)}
355
+ </button>
356
+ </div>
357
+ </div>
358
+ </devtools-report-section>`;
359
+ // clang-format on
360
+ }
361
+
362
+ function renderBadge(config: Badge): LitTemplate {
363
+ const badge = (klass: string, iconName: string, message: string): LitTemplate => {
364
+ // Disabled until https://crbug.com/1079231 is fixed.
365
+ // clang-format off
366
+ return html`
367
+ <span class=${klass}>
368
+ <devtools-icon name=${iconName}></devtools-icon>
369
+ <span>
370
+ ${message}
371
+ </span>
372
+ </span>
373
+ `;
374
+ // clang-format on
375
+ };
376
+ switch (config.type) {
377
+ case 'success': {
378
+ let message;
379
+ if (config.count === undefined) {
380
+ message = i18nString(UIStrings.badgeSuccess);
381
+ } else {
382
+ message = i18nString(UIStrings.badgeSuccessWithCount, {n: config.count});
383
+ }
384
+ return badge('status-badge status-badge-success', 'check-circle', message);
385
+ }
386
+ case 'failure': {
387
+ let message;
388
+ if (config.count === undefined) {
389
+ message = i18nString(UIStrings.badgeFailure);
390
+ } else {
391
+ message = i18nString(UIStrings.badgeFailureWithCount, {n: config.count});
392
+ }
393
+ return badge('status-badge status-badge-failure', 'cross-circle', message);
394
+ }
395
+ case 'neutral':
396
+ return badge('status-badge status-badge-neutral', 'clear', config.message);
397
+ }
398
+ }
399
+
400
+ type View = (input: ViewInput, output: undefined, target: HTMLElement|ShadowRoot) => void;
401
+
402
+ const DEFAULT_VIEW: View =
403
+ ({speculativeLoadingStatusData, speculationsInitiatedSummaryData}: ViewInput, output, target): void => {
404
+ // Disabled until https://crbug.com/1079231 is fixed.
405
+ // clang-format off
406
+ render(html`
407
+ <style>${usedPreloadingStyles}</style>
408
+ <devtools-report>
409
+ ${renderSpeculativeLoadingStatusForThisPageSections(speculativeLoadingStatusData)}
410
+
411
+ <devtools-report-divider></devtools-report-divider>
412
+
413
+ ${renderSpeculationsInitiatedByThisPageSummarySections(speculationsInitiatedSummaryData)}
414
+
415
+ <devtools-report-divider></devtools-report-divider>
416
+
417
+ <devtools-report-section>
418
+ <x-link
419
+ class="link devtools-link"
420
+ href=${'https://developer.chrome.com/blog/prerender-pages/'}
421
+ jslog=${VisualLogging.link()
422
+ .track({ click: true, keydown: 'Enter|Space' })
423
+ .context('learn-more')}
424
+ >${i18nString(UIStrings.learnMore)}</x-link>
425
+ </devtools-report-section>
426
+ </devtools-report>`, target, {host: target instanceof ShadowRoot ? target.host : undefined});
427
+ // clang-format on
428
+ };
429
+
157
430
  /**
158
431
  * TODO(kenoss): Rename this class and file once https://crrev.com/c/4933567 landed.
159
432
  * This also shows summary of speculations initiated by this page.
160
433
  **/
161
434
  export class UsedPreloadingView extends LegacyWrapper.LegacyWrapper.WrappableComponent<UI.Widget.VBox> {
162
435
  readonly #shadow = this.attachShadow({mode: 'open'});
436
+ readonly #view: View;
437
+
438
+ constructor(view = DEFAULT_VIEW) {
439
+ super();
440
+ this.#view = view;
441
+ }
442
+
163
443
  #data: UsedPreloadingViewData = {
164
444
  pageURL: '' as Platform.DevToolsPath.UrlString,
165
445
  previousAttempts: [],
@@ -172,51 +452,26 @@ export class UsedPreloadingView extends LegacyWrapper.LegacyWrapper.WrappableCom
172
452
  }
173
453
 
174
454
  async #render(): Promise<void> {
455
+ const viewInput: ViewInput = {
456
+ speculativeLoadingStatusData: this.#getSpeculativeLoadingStatusForThisPageData(),
457
+ speculationsInitiatedSummaryData: this.#getSpeculationsInitiatedByThisPageSummaryData(),
458
+ };
175
459
  await RenderCoordinator.write('UsedPreloadingView render', () => {
176
- Lit.render(this.#renderTemplate(), this.#shadow, {host: this});
460
+ this.#view(viewInput, undefined, this.#shadow);
177
461
  });
178
462
  }
179
463
 
180
- #renderTemplate(): Lit.LitTemplate {
181
- // Disabled until https://crbug.com/1079231 is fixed.
182
- // clang-format off
183
- return html`
184
- <style>${usedPreloadingStyles}</style>
185
- <devtools-report>
186
- ${this.#speculativeLoadingStatusForThisPageSections()}
187
-
188
- <devtools-report-divider></devtools-report-divider>
189
-
190
- ${this.#speculationsInitiatedByThisPageSummarySections()}
191
-
192
- <devtools-report-divider></devtools-report-divider>
193
-
194
- <devtools-report-section>
195
- <x-link
196
- class="link devtools-link"
197
- href=${'https://developer.chrome.com/blog/prerender-pages/'}
198
- jslog=${VisualLogging.link()
199
- .track({ click: true, keydown: 'Enter|Space' })
200
- .context('learn-more')}
201
- >${i18nString(UIStrings.learnMore)}</x-link>
202
- </devtools-report-section>
203
- </devtools-report>
204
- `;
205
- // clang-format on
206
- }
207
-
208
464
  #isPrerenderLike(speculationAction: Protocol.Preload.SpeculationAction): boolean {
209
465
  return [
210
466
  Protocol.Preload.SpeculationAction.Prerender, Protocol.Preload.SpeculationAction.PrerenderUntilScript
211
467
  ].includes(speculationAction);
212
468
  }
213
469
 
214
- #isPrerenderAttempt(attempt: SDK.PreloadingModel.PreloadingAttempt):
215
- attempt is SDK.PreloadingModel.PrerenderAttempt|SDK.PreloadingModel.PrerenderUntilScriptAttempt {
470
+ #isPrerenderAttempt(attempt: SDK.PreloadingModel.PreloadingAttempt): attempt is AttemptWithMismatchedHeaders {
216
471
  return this.#isPrerenderLike(attempt.action);
217
472
  }
218
473
 
219
- #speculativeLoadingStatusForThisPageSections(): Lit.LitTemplate {
474
+ #getSpeculativeLoadingStatusForThisPageData(): SpeculativeLoadingStatusForThisPageData {
220
475
  const pageURL = Common.ParsedURL.ParsedURL.urlWithoutHash(this.#data.pageURL);
221
476
  const forThisPage = this.#data.previousAttempts.filter(
222
477
  attempt => Common.ParsedURL.ParsedURL.urlWithoutHash(attempt.key.url) === pageURL);
@@ -244,84 +499,18 @@ export class UsedPreloadingView extends LegacyWrapper.LegacyWrapper.WrappableCom
244
499
  kind = UsedKind.NO_PRELOADS;
245
500
  }
246
501
 
247
- let badge;
248
- let basicMessage;
249
- switch (kind) {
250
- case UsedKind.DOWNGRADED_PRERENDER_TO_PREFETCH_AND_USED:
251
- badge = this.#badgeSuccess();
252
- basicMessage = html`${i18nString(UIStrings.downgradedPrefetchUsed)}`;
253
- break;
254
- case UsedKind.PREFETCH_USED:
255
- badge = this.#badgeSuccess();
256
- basicMessage = html`${i18nString(UIStrings.prefetchUsed)}`;
257
- break;
258
- case UsedKind.PRERENDER_USED:
259
- badge = this.#badgeSuccess();
260
- basicMessage = html`${i18nString(UIStrings.prerenderUsed)}`;
261
- break;
262
- case UsedKind.PREFETCH_FAILED:
263
- badge = this.#badgeFailure();
264
- basicMessage = html`${i18nString(UIStrings.prefetchFailed)}`;
265
- break;
266
- case UsedKind.PRERENDER_FAILED:
267
- badge = this.#badgeFailure();
268
- basicMessage = html`${i18nString(UIStrings.prerenderFailed)}`;
269
- break;
270
- case UsedKind.NO_PRELOADS:
271
- badge = this.#badgeNeutral(i18nString(UIStrings.badgeNoSpeculativeLoads));
272
- basicMessage = html`${i18nString(UIStrings.noPreloads)}`;
273
- break;
274
- }
275
-
276
- let maybeFailureReasonMessage;
277
- if (kind === UsedKind.PREFETCH_FAILED) {
278
- assertNotNullOrUndefined(prefetch);
279
- maybeFailureReasonMessage = prefetchFailureReason(prefetch as SDK.PreloadingModel.PrefetchAttempt);
280
- } else if (kind === UsedKind.PRERENDER_FAILED || kind === UsedKind.DOWNGRADED_PRERENDER_TO_PREFETCH_AND_USED) {
281
- assertNotNullOrUndefined(prerenderLike);
282
- maybeFailureReasonMessage = prerenderFailureReason(
283
- prerenderLike as SDK.PreloadingModel.PrerenderAttempt | SDK.PreloadingModel.PrerenderUntilScriptAttempt);
284
- }
285
-
286
- let maybeFailureReason: Lit.LitTemplate = Lit.nothing;
287
- if (maybeFailureReasonMessage !== undefined) {
288
- // Disabled until https://crbug.com/1079231 is fixed.
289
- // clang-format off
290
- maybeFailureReason = html`
291
- <devtools-report-section-header>${i18nString(UIStrings.detailsFailureReason)}</devtools-report-section-header>
292
- <devtools-report-section>
293
- ${maybeFailureReasonMessage}
294
- </devtools-report-section>
295
- `;
296
- // clang-format on
297
- }
298
-
299
- // Disabled until https://crbug.com/1079231 is fixed.
300
- // clang-format off
301
- return html`
302
- <devtools-report-section-header>${i18nString(UIStrings.speculativeLoadingStatusForThisPage)}</devtools-report-section-header>
303
- <devtools-report-section>
304
- <div>
305
- <div class="status-badge-container">
306
- ${badge}
307
- </div>
308
- <div>
309
- ${basicMessage}
310
- </div>
311
- </div>
312
- </devtools-report-section>
313
-
314
- ${maybeFailureReason}
315
-
316
- ${this.#maybeMismatchedSections(kind)}
317
- ${this.#maybeMismatchedHTTPHeadersSections()}
318
- `;
319
- // clang-format on
502
+ return {
503
+ kind,
504
+ prefetch,
505
+ prerenderLike,
506
+ mismatchedData: this.#getMismatchedData(kind),
507
+ attemptWithMismatchedHeaders: this.#getAttemptWithMismatchedHeaders(),
508
+ };
320
509
  }
321
510
 
322
- #maybeMismatchedSections(kind: UsedKind): Lit.LitTemplate {
511
+ #getMismatchedData(kind: UsedKind): MismatchedData|undefined {
323
512
  if (kind !== UsedKind.NO_PRELOADS || this.#data.previousAttempts.length === 0) {
324
- return Lit.nothing;
513
+ return undefined;
325
514
  }
326
515
 
327
516
  const rows = this.#data.previousAttempts.map(attempt => {
@@ -331,43 +520,19 @@ export class UsedPreloadingView extends LegacyWrapper.LegacyWrapper.WrappableCom
331
520
  status: attempt.status,
332
521
  };
333
522
  });
334
- const data = {
523
+ return {
335
524
  pageURL: this.#data.pageURL,
336
525
  rows,
337
526
  };
338
-
339
- // Disabled until https://crbug.com/1079231 is fixed.
340
- // clang-format off
341
- return html`
342
- <devtools-report-section-header>${i18nString(UIStrings.currentURL)}</devtools-report-section-header>
343
- <devtools-report-section>
344
- <x-link
345
- class="link devtools-link"
346
- href=${this.#data.pageURL}
347
- jslog=${VisualLogging.link()
348
- .track({ click: true, keydown: 'Enter|Space' })
349
- .context('current-url')}
350
- >${this.#data.pageURL}</x-link>
351
- </devtools-report-section>
352
-
353
- <devtools-report-section-header>${i18nString(UIStrings.preloadedURLs)}</devtools-report-section-header>
354
- <devtools-report-section
355
- jslog=${VisualLogging.section('preloaded-urls')}>
356
- <devtools-widget
357
- .widgetConfig=${UI.Widget.widgetConfig(MismatchedPreloadingGrid.MismatchedPreloadingGrid, {data})}
358
- ></devtools-widget>
359
- </devtools-report-section>
360
- `;
361
- // clang-format on
362
527
  }
363
528
 
364
- #maybeMismatchedHTTPHeadersSections(): Lit.LitTemplate {
529
+ #getAttemptWithMismatchedHeaders(): AttemptWithMismatchedHeaders|undefined {
365
530
  const attempt = this.#data.previousAttempts.find(
366
531
  attempt => this.#isPrerenderAttempt(attempt) && attempt.mismatchedHeaders !== null) as
367
532
  SDK.PreloadingModel.PrerenderAttempt |
368
533
  SDK.PreloadingModel.PrerenderUntilScriptAttempt | undefined;
369
534
  if (!attempt?.mismatchedHeaders) {
370
- return Lit.nothing;
535
+ return undefined;
371
536
  }
372
537
 
373
538
  if (attempt.key.url !== this.#data.pageURL) {
@@ -377,42 +542,10 @@ export class UsedPreloadingView extends LegacyWrapper.LegacyWrapper.WrappableCom
377
542
  throw new Error('unreachable');
378
543
  }
379
544
 
380
- // Disabled until https://crbug.com/1079231 is fixed.
381
- // clang-format off
382
- return html`
383
- <devtools-report-section-header>${i18nString(UIStrings.mismatchedHeadersDetail)}</devtools-report-section-header>
384
- <devtools-report-section>
385
- <style>${preloadingGridStyles}</style>
386
- <div class="preloading-container">
387
- <devtools-data-grid striped inline>
388
- <table>
389
- <tr>
390
- <th id="header-name" weight="30" sortable>
391
- ${i18nString(UIStrings.headerName)}
392
- </th>
393
- <th id="initial-value" weight="30" sortable>
394
- ${i18nString(UIStrings.initialNavigationValue)}
395
- </th>
396
- <th id="activation-value" weight="30" sortable>
397
- ${i18nString(UIStrings.activationNavigationValue)}
398
- </th>
399
- </tr>
400
- ${attempt.mismatchedHeaders.map(mismatchedHeaders => html`
401
- <tr>
402
- <td>${mismatchedHeaders.headerName}</td>
403
- <td>${mismatchedHeaders.initialValue ?? i18nString(UIStrings.missing)}</td>
404
- <td>${mismatchedHeaders.activationValue ?? i18nString(UIStrings.missing)}</td>
405
- </tr>
406
- `)}
407
- </table>
408
- </devtools-data-grid>
409
- </div>
410
- </devtools-report-section>
411
- `;
412
- // clang-format on
545
+ return attempt;
413
546
  }
414
547
 
415
- #speculationsInitiatedByThisPageSummarySections(): Lit.LitTemplate {
548
+ #getSpeculationsInitiatedByThisPageSummaryData(): SpeculationsInitiatedByThisPageSummaryData {
416
549
  const count = this.#data.currentAttempts.reduce((acc, attempt) => {
417
550
  acc.set(attempt.status, (acc.get(attempt.status) ?? 0) + 1);
418
551
  return acc;
@@ -422,21 +555,22 @@ export class UsedPreloadingView extends LegacyWrapper.LegacyWrapper.WrappableCom
422
555
  const failureCount = count.get(SDK.PreloadingModel.PreloadingStatus.FAILURE) ?? 0;
423
556
  const inProgressCount = (count.get(SDK.PreloadingModel.PreloadingStatus.PENDING) ?? 0) +
424
557
  (count.get(SDK.PreloadingModel.PreloadingStatus.RUNNING) ?? 0);
425
- const badges = [];
558
+
559
+ const badges: Badge[] = [];
426
560
  if (this.#data.currentAttempts.length === 0) {
427
- badges.push(this.#badgeNeutral(i18nString(UIStrings.badgeNoSpeculativeLoads)));
561
+ badges.push({type: 'neutral', message: i18nString(UIStrings.badgeNoSpeculativeLoads)});
428
562
  }
429
563
  if (notTriggeredCount > 0) {
430
- badges.push(this.#badgeNeutral(i18nString(UIStrings.badgeNotTriggeredWithCount, {n: notTriggeredCount})));
564
+ badges.push({type: 'neutral', message: i18nString(UIStrings.badgeNotTriggeredWithCount, {n: notTriggeredCount})});
431
565
  }
432
566
  if (inProgressCount > 0) {
433
- badges.push(this.#badgeNeutral(i18nString(UIStrings.badgeInProgressWithCount, {n: inProgressCount})));
567
+ badges.push({type: 'neutral', message: i18nString(UIStrings.badgeInProgressWithCount, {n: inProgressCount})});
434
568
  }
435
569
  if (readyCount > 0) {
436
- badges.push(this.#badgeSuccess(readyCount));
570
+ badges.push({type: 'success', count: readyCount});
437
571
  }
438
572
  if (failureCount > 0) {
439
- badges.push(this.#badgeFailure(failureCount));
573
+ badges.push({type: 'failure', count: failureCount});
440
574
  }
441
575
 
442
576
  const revealRuleSetView = (): void => {
@@ -446,69 +580,7 @@ export class UsedPreloadingView extends LegacyWrapper.LegacyWrapper.WrappableCom
446
580
  void Common.Revealer.reveal(new PreloadingHelper.PreloadingForward.AttemptViewWithFilter(null));
447
581
  };
448
582
 
449
- // Disabled until https://crbug.com/1079231 is fixed.
450
- // clang-format off
451
- return html`
452
- <devtools-report-section-header>${i18nString(UIStrings.speculationsInitiatedByThisPage)}</devtools-report-section-header>
453
- <devtools-report-section>
454
- <div>
455
- <div class="status-badge-container">
456
- ${badges}
457
- </div>
458
-
459
- <div class="reveal-links">
460
- <button class="link devtools-link" @click=${revealRuleSetView}
461
- jslog=${VisualLogging.action('view-all-rules').track({click: true})}>
462
- ${i18nString(UIStrings.viewAllRules)}
463
- </button>
464
-
465
- <button class="link devtools-link" @click=${revealAttemptViewWithFilter}
466
- jslog=${VisualLogging.action('view-all-speculations').track({click: true})}>
467
- ${i18nString(UIStrings.viewAllSpeculations)}
468
- </button>
469
- </div>
470
- </div>
471
- </devtools-report-section>
472
- `;
473
- // clang-format on
474
- }
475
-
476
- #badgeSuccess(count?: number): Lit.LitTemplate {
477
- let message;
478
- if (count === undefined) {
479
- message = i18nString(UIStrings.badgeSuccess);
480
- } else {
481
- message = i18nString(UIStrings.badgeSuccessWithCount, {n: count});
482
- }
483
- return this.#badge('status-badge status-badge-success', 'check-circle', message);
484
- }
485
-
486
- #badgeFailure(count?: number): Lit.LitTemplate {
487
- let message;
488
- if (count === undefined) {
489
- message = i18nString(UIStrings.badgeFailure);
490
- } else {
491
- message = i18nString(UIStrings.badgeFailureWithCount, {n: count});
492
- }
493
- return this.#badge('status-badge status-badge-failure', 'cross-circle', message);
494
- }
495
-
496
- #badgeNeutral(message: string): Lit.LitTemplate {
497
- return this.#badge('status-badge status-badge-neutral', 'clear', message);
498
- }
499
-
500
- #badge(klass: string, iconName: string, message: string): Lit.LitTemplate {
501
- // Disabled until https://crbug.com/1079231 is fixed.
502
- // clang-format off
503
- return html`
504
- <span class=${klass}>
505
- <devtools-icon name=${iconName}></devtools-icon>
506
- <span>
507
- ${message}
508
- </span>
509
- </span>
510
- `;
511
- // clang-format on
583
+ return {badges, revealRuleSetView, revealAttemptViewWithFilter};
512
584
  }
513
585
  }
514
586
 
@@ -422,7 +422,8 @@ export class MenuItem extends HTMLElement {
422
422
  readonly #shadow = this.attachShadow({mode: 'open'});
423
423
  connectedCallback(): void {
424
424
  this.tabIndex = 0;
425
- this.setAttribute('role', 'menuitem');
425
+ this.setAttribute('role', 'option');
426
+ this.setAttribute('aria-selected', String(this.#props.selected));
426
427
  }
427
428
  #props: MenuItemData = {
428
429
  value: '',
@@ -455,6 +456,7 @@ export class MenuItem extends HTMLElement {
455
456
 
456
457
  set selected(selected: boolean) {
457
458
  this.#props.selected = selected;
459
+ this.setAttribute('aria-selected', String(selected));
458
460
  void ComponentHelpers.ScheduledRender.scheduleRender(this, this.#render);
459
461
  }
460
462
 
package/package.json CHANGED
@@ -104,5 +104,5 @@
104
104
  "flat-cache": "6.1.12"
105
105
  }
106
106
  },
107
- "version": "1.0.1567721"
107
+ "version": "1.0.1568190"
108
108
  }