Skip to content

Commit b5df6a3

Browse files
committed
Persist pins when exporting/importing to HAR
1 parent a068fab commit b5df6a3

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/model/events/events-store.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,8 @@ export class EventsStore {
562562
requests,
563563
responses,
564564
aborts,
565-
tlsErrors
565+
tlsErrors,
566+
pinnedIds
566567
} = await parseHar(harContents).catch((harParseError: HarParseError) => {
567568
// Log all suberrors, for easier reporting & debugging.
568569
// This does not include HAR data - only schema errors like
@@ -590,6 +591,14 @@ export class EventsStore {
590591
);
591592

592593
this.queueEventFlush();
594+
595+
if (pinnedIds.length) {
596+
// This rAF will be scheduled after the queued flush, so the event should
597+
// always be fully imported by this stage:
598+
requestAnimationFrame(action(() => pinnedIds.forEach((id) => {
599+
this.events.find(e => e.id === id)!.pinned = true;
600+
})));
601+
}
593602
}
594603

595604
}

src/model/http/har.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ export interface Har extends HarFormat.Har {
3232
interface HarLog extends HarFormat.Log {
3333
// Custom field to expose failed TLS connections
3434
_tlsErrors: HarTlsErrorEntry[];
35+
36+
// Our extended version of HAR entries:
37+
entries: HarEntry[];
3538
}
3639

3740
export type RequestContentData = {
@@ -49,7 +52,10 @@ export interface ExtendedHarRequest extends HarFormat.Request {
4952
_content?: RequestContentData;
5053
}
5154

52-
export type HarEntry = HarFormat.Entry;
55+
export interface HarEntry extends HarFormat.Entry {
56+
_pinned?: true;
57+
}
58+
5359
export type HarTlsErrorEntry = {
5460
startedDateTime: string;
5561
time: number; // Floating-point high-resolution duration, in ms
@@ -345,7 +351,8 @@ async function generateHarEntry(exchange: HttpExchange): Promise<HarEntry> {
345351
send: Math.max(sendDuration, 0),
346352
wait: Math.max(waitDuration, 0),
347353
receive: Math.max(receiveDuration, 0)
348-
}
354+
},
355+
_pinned: exchange.pinned || undefined
349356
};
350357
}
351358

@@ -375,6 +382,7 @@ export type ParsedHar = {
375382
responses: HarResponse[],
376383
aborts: HarRequest[],
377384
tlsErrors: InputTLSRequest[]
385+
pinnedIds: string[]
378386
};
379387

380388
const sumTimings = (
@@ -396,6 +404,7 @@ export async function parseHar(harContents: unknown): Promise<ParsedHar> {
396404
const responses: HarResponse[] = [];
397405
const aborts: HarRequest[] = [];
398406
const tlsErrors: InputTLSRequest[] = [];
407+
const pinnedIds: string[] = []
399408

400409
har.log.entries.forEach((entry, i) => {
401410
const id = baseId + i;
@@ -429,6 +438,8 @@ export async function parseHar(harContents: unknown): Promise<ParsedHar> {
429438
} else {
430439
aborts.push(request);
431440
}
441+
442+
if (entry._pinned) pinnedIds.push(id);
432443
});
433444

434445
if (har.log._tlsErrors) {
@@ -448,7 +459,7 @@ export async function parseHar(harContents: unknown): Promise<ParsedHar> {
448459
});
449460
}
450461

451-
return { requests, responses, aborts, tlsErrors };
462+
return { requests, responses, aborts, tlsErrors, pinnedIds };
452463
}
453464

454465
// Mutatively cleans & returns the HAR, to tidy up irrelevant but potentially

0 commit comments

Comments
 (0)