Skip to content

Commit 15cc5ee

Browse files
monica-chDevtools-frontend LUCI CQ
authored andcommitted
Add ServiceWorker Static Routing API information in HAR.
Currently static routing api info is not available upon HAR export. So, this cl adds following custom fields that has routing info to the HAR response and timing property. - serviceWorkerRouterRuleIdMatched - serviceWorkerRouterMatchedSourceType - serviceWorkerRouterActualSourceType - workerRouterEvaluationStart - workerCacheLookupStart per https://docs.google.com/document/d/1aVRdEGQiCsWjEwgU6W9Lz7b1AtxxJXybWjPkmMvYURA/edit?tab=t.0 After this CL, HAR contains ServiceWorkerRouterInfo under response and timing fields, and the timing view shows service worker routing info (id/matched/actual/evalaution/cache lookup) when imported HAR. Bug: 375515693 Change-Id: Ic63ccefc27edc35b3305d144bc28cb3dcff599c0 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6334706 Reviewed-by: Shunya Shishido <[email protected]> Reviewed-by: Yoshisato Yanagisawa <[email protected]> Commit-Queue: Monica Chintala <[email protected]> Reviewed-by: Benedikt Meurer <[email protected]>
1 parent 0cefdd7 commit 15cc5ee

File tree

5 files changed

+61
-0
lines changed

5 files changed

+61
-0
lines changed

front_end/models/har/HARFormat.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,12 @@ class HARResponse extends HARBase {
254254
this.custom.set('fetchedViaServiceWorker', Boolean(data['_fetchedViaServiceWorker']));
255255
this.custom.set('responseCacheStorageCacheName', HARBase.optionalString(data['_responseCacheStorageCacheName']));
256256
this.custom.set('serviceWorkerResponseSource', HARBase.optionalString(data['_serviceWorkerResponseSource']));
257+
this.custom.set(
258+
'serviceWorkerRouterRuleIdMatched', HARBase.optionalNumber(data['_serviceWorkerRouterRuleIdMatched']));
259+
this.custom.set(
260+
'serviceWorkerRouterMatchedSourceType', HARBase.optionalString(data['_serviceWorkerRouterMatchedSourceType']));
261+
this.custom.set(
262+
'serviceWorkerRouterActualSourceType', HARBase.optionalString(data['_serviceWorkerRouterActualSourceType']));
257263
}
258264
}
259265

@@ -380,6 +386,8 @@ export class HARTimings extends HARBase {
380386
this.custom.set('workerReady', HARBase.optionalNumber(data['_workerReady']));
381387
this.custom.set('workerFetchStart', HARBase.optionalNumber(data['_workerFetchStart']));
382388
this.custom.set('workerRespondWithSettled', HARBase.optionalNumber(data['_workerRespondWithSettled']));
389+
this.custom.set('workerRouterEvaluationStart', HARBase.optionalNumber(data['_workerRouterEvaluationStart']));
390+
this.custom.set('workerCacheLookupStart', HARBase.optionalNumber(data['_workerCacheLookupStart']));
383391
}
384392
}
385393

front_end/models/har/Importer.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ const exampleLog = new HAR.HARFormat.HARLog({
9898
_fetchedViaServiceWorker: true,
9999
_responseCacheStorageCacheName: 'v1',
100100
_serviceWorkerResponseSource: 'cache-storage',
101+
_serviceWorkerRouterRuleIdMatched: 1,
102+
_serviceWorkerRouterMatchedSourceType: 'cache',
103+
_serviceWorkerRouterActualSourceType: 'network',
101104
},
102105
serverIPAddress: '127.0.0.1',
103106
startedDateTime: '2020-12-14T17:35:53.241Z',
@@ -115,6 +118,8 @@ const exampleLog = new HAR.HARFormat.HARLog({
115118
_workerReady: 2,
116119
_workerFetchStart: 10,
117120
_workerRespondWithSettled: 300,
121+
_workerRouterEvaluationStart: 100,
122+
_workerCacheLookupStart: 200,
118123
},
119124
},
120125
{
@@ -261,6 +266,9 @@ describe('HAR Importer', () => {
261266
assert.isTrue(parsedRequest.fetchedViaServiceWorker);
262267
assert.strictEqual(parsedRequest.getResponseCacheStorageCacheName(), 'v1');
263268
assert.strictEqual(parsedRequest.serviceWorkerResponseSource(), 'cache-storage');
269+
assert.strictEqual(parsedRequest.serviceWorkerRouterInfo?.ruleIdMatched, 1);
270+
assert.strictEqual(parsedRequest.serviceWorkerRouterInfo?.matchedSourceType, 'cache');
271+
assert.strictEqual(parsedRequest.serviceWorkerRouterInfo?.actualSourceType, 'network');
264272
});
265273

266274
it('Parses the request timings', () => {
@@ -286,6 +294,8 @@ describe('HAR Importer', () => {
286294
workerFetchStart: 10,
287295
workerRespondWithSettled: 300,
288296
workerStart: 30,
297+
workerRouterEvaluationStart: 100,
298+
workerCacheLookupStart: 200,
289299
});
290300
});
291301

front_end/models/har/Importer.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,20 @@ export class Importer {
172172
request.setResponseCacheStorageCacheName(responseCacheStorageCacheName);
173173
}
174174

175+
const ruleIdMatched = entry.response.customAsNumber('serviceWorkerRouterRuleIdMatched');
176+
// The router rule ID is 1-indexed. We add router related optional fields
177+
// only when there is a matched router rule.
178+
if (ruleIdMatched !== undefined) {
179+
const routerInfo: Protocol.Network.ServiceWorkerRouterInfo = {
180+
ruleIdMatched,
181+
matchedSourceType: entry.response.customAsString('serviceWorkerRouterMatchedSourceType') as
182+
Protocol.Network.ServiceWorkerRouterSource,
183+
actualSourceType: entry.response.customAsString('serviceWorkerRouterActualSourceType') as
184+
Protocol.Network.ServiceWorkerRouterSource,
185+
};
186+
request.serviceWorkerRouterInfo = routerInfo;
187+
}
188+
175189
request.finished = true;
176190
}
177191

@@ -250,6 +264,8 @@ export class Importer {
250264
workerReady: timings.customAsNumber('workerReady') || -1,
251265
workerFetchStart: timings.customAsNumber('workerFetchStart') || -1,
252266
workerRespondWithSettled: timings.customAsNumber('workerRespondWithSettled') || -1,
267+
workerRouterEvaluationStart: timings.customAsNumber('workerRouterEvaluationStart'),
268+
workerCacheLookupStart: timings.customAsNumber('workerCacheLookupStart'),
253269

254270
sendStart: timings.send >= 0 ? lastEntry : -1,
255271
sendEnd: accumulateTime(timings.send),

front_end/models/har/Log.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,13 @@ describe('HAR', () => {
151151
request.setResponseCacheStorageCacheName(cacheName);
152152
request.setServiceWorkerResponseSource(Protocol.Network.ServiceWorkerResponseSource.CacheStorage);
153153

154+
const serviceWorkerRouterInfo: Protocol.Network.ServiceWorkerRouterInfo = {
155+
ruleIdMatched: 1,
156+
matchedSourceType: Protocol.Network.ServiceWorkerRouterSource.Cache,
157+
actualSourceType: Protocol.Network.ServiceWorkerRouterSource.Network,
158+
};
159+
request.serviceWorkerRouterInfo = serviceWorkerRouterInfo;
160+
154161
const timingInfo: Protocol.Network.ResourceTiming = {
155162
requestTime: 500,
156163
proxyStart: 0,
@@ -171,6 +178,8 @@ describe('HAR', () => {
171178
pushEnd: 0,
172179
receiveHeadersStart: 0,
173180
receiveHeadersEnd: 0,
181+
workerRouterEvaluationStart: 200,
182+
workerCacheLookupStart: 100,
174183
};
175184
request.timing = timingInfo;
176185

@@ -180,11 +189,18 @@ describe('HAR', () => {
180189
assert.strictEqual(entry.response._responseCacheStorageCacheName, cacheName);
181190
assert.strictEqual(
182191
entry.response._serviceWorkerResponseSource, Protocol.Network.ServiceWorkerResponseSource.CacheStorage);
192+
assert.strictEqual(entry.response._serviceWorkerRouterRuleIdMatched, serviceWorkerRouterInfo.ruleIdMatched);
193+
assert.strictEqual(
194+
entry.response._serviceWorkerRouterMatchedSourceType, serviceWorkerRouterInfo.matchedSourceType);
195+
assert.strictEqual(
196+
entry.response._serviceWorkerRouterActualSourceType, serviceWorkerRouterInfo.actualSourceType);
183197

184198
assert.strictEqual(entry.timings._workerStart, timingInfo.workerStart);
185199
assert.strictEqual(entry.timings._workerReady, timingInfo.workerReady);
186200
assert.strictEqual(entry.timings._workerFetchStart, timingInfo.workerFetchStart);
187201
assert.strictEqual(entry.timings._workerRespondWithSettled, timingInfo.workerRespondWithSettled);
202+
assert.strictEqual(entry.timings._workerRouterEvaluationStart, timingInfo.workerRouterEvaluationStart);
203+
assert.strictEqual(entry.timings._workerCacheLookupStart, timingInfo.workerCacheLookupStart);
188204
});
189205
});
190206
});

front_end/models/har/Log.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ export class Entry {
235235

236236
private buildResponse(): Response {
237237
const headersText = this.request.responseHeadersText;
238+
238239
return {
239240
status: this.request.statusCode,
240241
statusText: this.request.statusText,
@@ -250,6 +251,9 @@ export class Entry {
250251
_fetchedViaServiceWorker: this.request.fetchedViaServiceWorker,
251252
_responseCacheStorageCacheName: this.request.getResponseCacheStorageCacheName(),
252253
_serviceWorkerResponseSource: this.request.serviceWorkerResponseSource(),
254+
_serviceWorkerRouterRuleIdMatched: this.request.serviceWorkerRouterInfo?.ruleIdMatched ?? undefined,
255+
_serviceWorkerRouterMatchedSourceType: this.request.serviceWorkerRouterInfo?.matchedSourceType ?? undefined,
256+
_serviceWorkerRouterActualSourceType: this.request.serviceWorkerRouterInfo?.actualSourceType ?? undefined,
253257
};
254258
}
255259

@@ -335,6 +339,8 @@ export class Entry {
335339
result._workerReady = timing.workerReady;
336340
result._workerFetchStart = timing.workerFetchStart;
337341
result._workerRespondWithSettled = timing.workerRespondWithSettled;
342+
result._workerRouterEvaluationStart = timing.workerRouterEvaluationStart;
343+
result._workerCacheLookupStart = timing.workerCacheLookupStart;
338344
} else if (this.request.responseReceivedTime === -1) {
339345
// Means that we don't have any more details after blocked, so attribute all to blocked.
340346
result.blocked = Entry.toMilliseconds(this.request.endTime - issueTime);
@@ -463,6 +469,8 @@ export interface Timing {
463469
_workerReady?: number;
464470
_workerFetchStart?: number;
465471
_workerRespondWithSettled?: number;
472+
_workerRouterEvaluationStart?: number;
473+
_workerCacheLookupStart?: number;
466474
}
467475

468476
export interface Parameter {
@@ -505,6 +513,9 @@ export interface Response {
505513
_fetchedViaServiceWorker: boolean;
506514
_responseCacheStorageCacheName: string|undefined;
507515
_serviceWorkerResponseSource: Protocol.Network.ServiceWorkerResponseSource|undefined;
516+
_serviceWorkerRouterRuleIdMatched: number|undefined;
517+
_serviceWorkerRouterMatchedSourceType: string|undefined;
518+
_serviceWorkerRouterActualSourceType: string|undefined;
508519
}
509520

510521
export interface EntryDTO {

0 commit comments

Comments
 (0)