Skip to content

Commit 776915e

Browse files
authored
fix: Record 0 for headerSize if transferSize is 0 (#496)
1 parent 31d8e30 commit 776915e

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

src/plugins/event-plugins/NavigationPlugin.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,10 @@ export class NavigationPlugin extends InternalPlugin {
253253

254254
duration: entryData.duration,
255255

256-
headerSize: entryData.transferSize - entryData.encodedBodySize,
256+
headerSize:
257+
entryData.transferSize > 0
258+
? entryData.transferSize - entryData.encodedBodySize
259+
: 0,
257260
transferSize: entryData.transferSize,
258261
compressionRatio:
259262
entryData.encodedBodySize > 0

src/plugins/event-plugins/__tests__/NavigationPlugin.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,23 @@ describe('NavigationPlugin tests', () => {
4646
);
4747
});
4848

49+
test('When transferSize is 0 then headerSize is 0', async () => {
50+
const plugin: NavigationPlugin = buildNavigationPlugin();
51+
// Run
52+
plugin.load(context);
53+
window.dispatchEvent(new Event('load'));
54+
plugin.disable();
55+
56+
expect(record.mock.calls[0][0]).toEqual(
57+
PERFORMANCE_NAVIGATION_EVENT_TYPE
58+
);
59+
expect(record.mock.calls[0][1]).toEqual(
60+
expect.objectContaining({
61+
headerSize: 0
62+
})
63+
);
64+
});
65+
4966
test('When navigation timing level 2 API is not present then navigation timing level 1 API is recorded', async () => {
5067
jest.useFakeTimers();
5168
mockPerformanceObjectWith([putRumEventsDocument], [], []);

src/test-utils/mock-data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const navigationEvent = {
4141
secureConnectionStart: 6.495000001450535,
4242
serverTiming: [],
4343
startTime: 0,
44-
transferSize: 36525,
44+
transferSize: 0,
4545
type: 'navigate',
4646
unloadEventEnd: 0,
4747
unloadEventStart: 0,

0 commit comments

Comments
 (0)