Skip to content

Commit

Permalink
fix: call mark if performance API exists (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioanna0 authored Mar 9, 2021
1 parent be73ead commit 4507201
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/EventTimer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit 4507201

Please sign in to comment.