From bc5db2c5cac4599c4427e590f5b05a94d71d058a Mon Sep 17 00:00:00 2001 From: Barry Pollard Date: Tue, 22 Oct 2024 19:11:40 +0100 Subject: [PATCH 1/2] Add guard against getEntriesByType --- src/lib/getNavigationEntry.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/getNavigationEntry.ts b/src/lib/getNavigationEntry.ts index 0573ce4f..8795a8a6 100644 --- a/src/lib/getNavigationEntry.ts +++ b/src/lib/getNavigationEntry.ts @@ -15,7 +15,11 @@ */ export const getNavigationEntry = (): PerformanceNavigationTiming | void => { - const navigationEntry = performance.getEntriesByType('navigation')[0]; + // JSDOM does not implement getEntriesByType: https://github.com/jsdom/jsdom/issues/3309 + const navigationEntry = + self.performance && + performance.getEntriesByType && + performance.getEntriesByType('navigation')[0]; // Check to ensure the `responseStart` property is present and valid. // In some cases a zero value is reported by the browser (for From 16f4a51ad53aa094490ec5f8811361b659d606b4 Mon Sep 17 00:00:00 2001 From: Barry Pollard Date: Tue, 22 Oct 2024 22:03:11 +0100 Subject: [PATCH 2/2] Review feedback --- src/lib/getNavigationEntry.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/lib/getNavigationEntry.ts b/src/lib/getNavigationEntry.ts index 8795a8a6..5a08124d 100644 --- a/src/lib/getNavigationEntry.ts +++ b/src/lib/getNavigationEntry.ts @@ -16,10 +16,7 @@ export const getNavigationEntry = (): PerformanceNavigationTiming | void => { // JSDOM does not implement getEntriesByType: https://github.com/jsdom/jsdom/issues/3309 - const navigationEntry = - self.performance && - performance.getEntriesByType && - performance.getEntriesByType('navigation')[0]; + const navigationEntry = performance.getEntriesByType?.('navigation')[0]; // Check to ensure the `responseStart` property is present and valid. // In some cases a zero value is reported by the browser (for