From 4507201ca22d9efddf35413edd8457b231f36fde Mon Sep 17 00:00:00 2001 From: Ioanna Kyprianou <51630004+ioanna0@users.noreply.github.com> Date: Tue, 9 Mar 2021 20:06:09 +0200 Subject: [PATCH] fix: call mark if performance API exists (#193) --- src/EventTimer.ts | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/EventTimer.ts b/src/EventTimer.ts index eedeb3ded..cc5ec8f86 100644 --- a/src/EventTimer.ts +++ b/src/EventTimer.ts @@ -106,18 +106,21 @@ export class EventTimer { }; } - mark(name: string): PerformanceEntry { + mark(name: string): void { const longName = `gu.commercial.${name}`; - window.performance.mark(longName); - - // Most recent mark with this name is the event we just created. - const mark = window.performance - .getEntriesByName(longName, 'mark') - .slice(-1)[0]; - if (typeof mark !== 'undefined') { - this.events.push(new Event(name, mark)); + if ( + typeof window.performance !== 'undefined' && + 'mark' in window.performance + ) { + window.performance.mark(longName); + // Most recent mark with this name is the event we just created. + const mark = window.performance + .getEntriesByName(longName, 'mark') + .slice(-1)[0]; + if (typeof mark !== 'undefined') { + this.events.push(new Event(name, mark)); + } } - return mark; } /**