Skip to content

Commit a0c721b

Browse files
committed
startTime & endTime
1 parent fc5b77a commit a0c721b

File tree

1 file changed

+37
-41
lines changed
  • packages/rrweb/src/plugins/network/record

1 file changed

+37
-41
lines changed

packages/rrweb/src/plugins/network/record/index.ts

Lines changed: 37 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,14 @@ const defaultNetworkOptions: NetworkRecordOptions = {
7878
type Headers = Record<string, string>;
7979

8080
type NetworkRequest = {
81-
requestUrl: string;
82-
requestMethod: string;
83-
requestInitiator: InitiatorType;
81+
url: string;
82+
method?: string;
83+
initiatorType: InitiatorType;
84+
status?: number;
85+
startTime: number;
86+
endTime: number;
8487
requestHeaders?: Headers;
8588
requestBody?: string | null;
86-
responseStatus?: number;
87-
responseDuration: number;
8889
responseHeaders?: Headers;
8990
responseBody?: string | null;
9091
};
@@ -127,15 +128,12 @@ function initPerformanceObserver(
127128
)),
128129
);
129130
cb({
130-
requests: initialPerformanceEntries.map((performanceEntry) => ({
131-
requestUrl: performanceEntry.name,
132-
requestMethod: 'GET',
133-
requestInitiator: performanceEntry.initiatorType as InitiatorType,
134-
responseStatus:
135-
'responseStatus' in performanceEntry
136-
? performanceEntry.responseStatus
137-
: undefined,
138-
responseDuration: Math.round(performanceEntry.duration),
131+
requests: initialPerformanceEntries.map((entry) => ({
132+
url: entry.name,
133+
initiatorType: entry.initiatorType as InitiatorType,
134+
status: 'responseStatus' in entry ? entry.responseStatus : undefined,
135+
startTime: Math.round(entry.startTime),
136+
endTime: Math.round(entry.responseEnd),
139137
})),
140138
isInitial: true,
141139
});
@@ -154,15 +152,12 @@ function initPerformanceObserver(
154152
entry.initiatorType !== 'fetch'),
155153
);
156154
cb({
157-
requests: performanceEntries.map((performanceEntry) => ({
158-
requestUrl: performanceEntry.name,
159-
requestMethod: 'GET',
160-
requestInitiator: performanceEntry.initiatorType as InitiatorType,
161-
responseStatus:
162-
'responseStatus' in performanceEntry
163-
? performanceEntry.responseStatus
164-
: undefined,
165-
responseDuration: Math.round(performanceEntry.duration),
155+
requests: performanceEntries.map((entry) => ({
156+
url: entry.name,
157+
initiatorType: entry.initiatorType as InitiatorType,
158+
status: 'responseStatus' in entry ? entry.responseStatus : undefined,
159+
startTime: Math.round(entry.startTime),
160+
endTime: Math.round(entry.responseEnd),
166161
})),
167162
});
168163
});
@@ -188,11 +183,11 @@ const getRequestPerformanceEntry = async (
188183
) as PerformanceResourceTiming[];
189184
const performanceEntry = findLast(
190185
urlPerformanceEntries,
191-
(performanceEntry) =>
192-
isResourceTiming(performanceEntry) &&
193-
performanceEntry.initiatorType === initiatorType &&
194-
(!after || performanceEntry.startTime >= after) &&
195-
(!before || performanceEntry.startTime <= before),
186+
(entry) =>
187+
isResourceTiming(entry) &&
188+
entry.initiatorType === initiatorType &&
189+
(!after || entry.startTime >= after) &&
190+
(!before || entry.startTime <= before),
196191
);
197192
if (!performanceEntry) {
198193
await new Promise((resolve) => setTimeout(resolve, 50 * attempt));
@@ -322,15 +317,16 @@ function initXhrObserver(
322317
after,
323318
before,
324319
)
325-
.then((performanceEntry) => {
320+
.then((entry) => {
326321
const request: NetworkRequest = {
327-
requestUrl: performanceEntry.name,
328-
requestMethod: req.method,
329-
requestInitiator: performanceEntry.initiatorType as InitiatorType,
322+
url: entry.name,
323+
method: req.method,
324+
initiatorType: entry.initiatorType as InitiatorType,
325+
status: xhr.status,
326+
startTime: Math.round(entry.startTime),
327+
endTime: Math.round(entry.responseEnd),
330328
requestHeaders: networkRequest.requestHeaders,
331329
requestBody: networkRequest.requestBody,
332-
responseStatus: xhr.status,
333-
responseDuration: performanceEntry.duration,
334330
responseHeaders: networkRequest.responseHeaders,
335331
responseBody: networkRequest.responseBody,
336332
};
@@ -409,7 +405,6 @@ function initFetchObserver(
409405
after = win.performance.now();
410406
res = await originalFetch(req);
411407
before = win.performance.now();
412-
networkRequest.responseStatus = res.status;
413408
if (recordResponseHeaders) {
414409
networkRequest.responseHeaders = {};
415410
res.headers.forEach((value, header) => {
@@ -437,15 +432,16 @@ function initFetchObserver(
437432
return res;
438433
} finally {
439434
getRequestPerformanceEntry(win, 'fetch', req.url, after, before)
440-
.then((performanceEntry) => {
435+
.then((entry) => {
441436
const request: NetworkRequest = {
442-
requestUrl: performanceEntry.name,
443-
requestMethod: req.method,
444-
requestInitiator: performanceEntry.initiatorType as InitiatorType,
437+
url: entry.name,
438+
method: req.method,
439+
initiatorType: entry.initiatorType as InitiatorType,
440+
status: res?.status,
441+
startTime: Math.round(entry.startTime),
442+
endTime: Math.round(entry.responseEnd),
445443
requestHeaders: networkRequest.requestHeaders,
446444
requestBody: networkRequest.requestBody,
447-
responseStatus: res?.status,
448-
responseDuration: performanceEntry.duration,
449445
responseHeaders: networkRequest.responseHeaders,
450446
responseBody: networkRequest.responseBody,
451447
};

0 commit comments

Comments
 (0)