From f673747671e9100dc9deea137e9ab3b4582eef4e Mon Sep 17 00:00:00 2001 From: Joe Tannenbaum Date: Wed, 15 Jan 2025 15:53:24 -0500 Subject: [PATCH] fix navigation type for safari 10 --- packages/core/src/navigationType.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/core/src/navigationType.ts b/packages/core/src/navigationType.ts index 449451796..0202b47e3 100644 --- a/packages/core/src/navigationType.ts +++ b/packages/core/src/navigationType.ts @@ -2,11 +2,23 @@ class NavigationType { protected type: NavigationTimingType public constructor() { - if (typeof window !== 'undefined' && window?.performance.getEntriesByType('navigation').length > 0) { - this.type = (window.performance.getEntriesByType('navigation')[0] as PerformanceNavigationTiming).type - } else { - this.type = 'navigate' + this.type = this.resolveType() + } + + protected resolveType(): NavigationTimingType { + if (typeof window === 'undefined') { + return 'navigate' } + + if ( + window.performance && + window.performance.getEntriesByType && + window.performance.getEntriesByType('navigation').length > 0 + ) { + return (window.performance.getEntriesByType('navigation')[0] as PerformanceNavigationTiming).type + } + + return 'navigate' } public get(): NavigationTimingType {