Skip to content

Commit d90efb8

Browse files
azaikaDevtools-frontend LUCI CQ
authored and
Devtools-frontend LUCI CQ
committed
[ServiceWorker] Change indicator on the Network panel in no-matching-routes case
This CL resolves crbug.com/406022417. Currently, the size column shows `(ServiceWorker router)` and displays `matched to router#0` by mouse hover when ServiceWorker static routers are registered for a request but no matching routes are found. After this CL, the size column shows network transfer sizes and displays `no matching ServerWorker routes` in no-matching-routes cases. See the crbug comments for the new UI appearance. This CL also applies i10n API to some existing code to maintain consistency of implementation. Bug: 406022417 Change-Id: Ifd10a702a8ca9044db66a4370e82ae48bf79540d Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6446936 Reviewed-by: Benedikt Meurer <bmeurer@chromium.org> Reviewed-by: Shunya Shishido <sisidovski@chromium.org> Commit-Queue: Takashi Nakayama <tnak@chromium.org>
1 parent 6e52074 commit d90efb8

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

front_end/core/sdk/NetworkRequest.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,16 @@ export class NetworkRequest extends Common.ObjectWrapper.ObjectWrapper<EventType
784784
this.#serviceWorkerRouterInfoInternal = x;
785785
}
786786

787+
/**
788+
* Returns true if the request was matched to a route when using the
789+
* ServiceWorker static routing API.
790+
*/
791+
hasMatchingServiceWorkerRouter(): boolean {
792+
// See definitions in `browser_protocol.pdl` for justification.
793+
return this.#serviceWorkerRouterInfoInternal !== undefined &&
794+
this.serviceWorkerRouterInfo?.matchedSourceType !== undefined;
795+
}
796+
787797
/**
788798
* Returns true if the request was sent by a service worker.
789799
*/

front_end/panels/network/NetworkDataGridNode.ts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,19 @@ const UIStrings = {
190190
*@description Text of a DOM element in Network Data Grid Node of the Network panel
191191
*/
192192
serviceWorker: '(`ServiceWorker`)',
193+
/**
194+
*@description Cell title in Network Data Grid Node of the Network panel
195+
*@example {4 B} PH1
196+
*@example {10 B} PH2
197+
*/
198+
servedFromNetwork: '{PH1} transferred over network, resource size: {PH2}',
199+
/**
200+
*@description Cell title in Network Data Grid Node of the Network panel
201+
*@example {4 B} PH1
202+
*@example {10 B} PH2
203+
*/
204+
servedFromNetworkMissingServiceWorkerRoute:
205+
'{PH1} transferred over network, resource size: {PH2}, no matching ServiceWorker routes',
193206
/**
194207
*@description Cell title in Network Data Grid Node of the Network panel
195208
*@example {4 B} PH1
@@ -1405,13 +1418,13 @@ export class NetworkRequestNode extends NetworkNode {
14051418
UI.UIUtils.createTextChild(cell, i18nString(UIStrings.memoryCache));
14061419
UI.Tooltip.Tooltip.install(cell, i18nString(UIStrings.servedFromMemoryCacheResource, {PH1: resourceSize}));
14071420
cell.classList.add('network-dim-cell');
1408-
} else if (this.requestInternal.serviceWorkerRouterInfo) {
1409-
const {serviceWorkerRouterInfo} = this.requestInternal;
1410-
// If `serviceWorkerRouterInfo.ruleIdMatched` is undefined,store 0 to indicate invalid ID.
1411-
const ruleIdMatched = serviceWorkerRouterInfo.ruleIdMatched ?? 0;
1421+
} else if (this.requestInternal.hasMatchingServiceWorkerRouter()) {
1422+
const ruleIdMatched = this.requestInternal.serviceWorkerRouterInfo?.ruleIdMatched as number;
1423+
const matchedSourceType =
1424+
this.requestInternal.serviceWorkerRouterInfo?.matchedSourceType as Protocol.Network.ServiceWorkerRouterSource;
14121425
UI.UIUtils.createTextChild(cell, i18n.i18n.lockedString('(ServiceWorker router)'));
14131426
let tooltipText;
1414-
if (serviceWorkerRouterInfo.matchedSourceType === Protocol.Network.ServiceWorkerRouterSource.Network) {
1427+
if (matchedSourceType === Protocol.Network.ServiceWorkerRouterSource.Network) {
14151428
const transferSize = i18n.ByteUtilities.formatBytesToKb(this.requestInternal.transferSize);
14161429
tooltipText = i18nString(
14171430
UIStrings.matchedToServiceWorkerRouterWithNetworkSource,
@@ -1421,6 +1434,14 @@ export class NetworkRequestNode extends NetworkNode {
14211434
}
14221435
UI.Tooltip.Tooltip.install(cell, tooltipText);
14231436
cell.classList.add('network-dim-cell');
1437+
} else if (this.requestInternal.serviceWorkerRouterInfo) {
1438+
// ServiceWorker routers are registered, but the request fallbacks to network
1439+
// because no matching router rules found.
1440+
const transferSize = i18n.ByteUtilities.formatBytesToKb(this.requestInternal.transferSize);
1441+
UI.UIUtils.createTextChild(cell, transferSize);
1442+
UI.Tooltip.Tooltip.install(
1443+
cell,
1444+
i18nString(UIStrings.servedFromNetworkMissingServiceWorkerRoute, {PH1: transferSize, PH2: resourceSize}));
14241445
} else if (this.requestInternal.fetchedViaServiceWorker) {
14251446
UI.UIUtils.createTextChild(cell, i18nString(UIStrings.serviceWorker));
14261447
UI.Tooltip.Tooltip.install(cell, i18nString(UIStrings.servedFromServiceWorkerResource, {PH1: resourceSize}));
@@ -1444,7 +1465,7 @@ export class NetworkRequestNode extends NetworkNode {
14441465
} else {
14451466
const transferSize = i18n.ByteUtilities.formatBytesToKb(this.requestInternal.transferSize);
14461467
UI.UIUtils.createTextChild(cell, transferSize);
1447-
UI.Tooltip.Tooltip.install(cell, `${transferSize} transferred over network, resource size: ${resourceSize}`);
1468+
UI.Tooltip.Tooltip.install(cell, i18nString(UIStrings.servedFromNetwork, {PH1: transferSize, PH2: resourceSize}));
14481469
}
14491470
this.appendSubtitle(cell, resourceSize);
14501471
}

0 commit comments

Comments
 (0)