Skip to content

Commit a0dd71a

Browse files
authored
fix(apm|tracing): Make sure Performance Observer takeRecords() is defined (#2825)
* fix(apm|tracing): Make sure Performance Observer takeRecords() is defined In Safari 14.0 and below, `PerformanceObserver.takeRecords()` is not defined. We should defend against it by checking for existence before usage. In the future, we may have to look for another way to track PO records for these browsers. Also occurs in IE 11.
1 parent e4b5782 commit a0dd71a

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44

55
- "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott
6+
- [apm/tracing] fix: Make sure Performance Observer takeRecords() is defined
67

78
## 5.21.1
89

packages/apm/src/integrations/tracing.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,9 @@ export class Tracing implements Integration {
760760
});
761761

762762
Tracing._forceLCP = (): void => {
763-
po.takeRecords().forEach(updateLCP);
763+
if (po.takeRecords) {
764+
po.takeRecords().forEach(updateLCP);
765+
}
764766
};
765767
} catch (e) {
766768
// Do nothing if the browser doesn't support this API.

packages/tracing/src/browser/metrics.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ export class MetricsInstrumentation {
170170
});
171171

172172
this._forceLCP = () => {
173-
po.takeRecords().forEach(updateLCP);
173+
if (po.takeRecords) {
174+
po.takeRecords().forEach(updateLCP);
175+
}
174176
};
175177
} catch (e) {
176178
// Do nothing if the browser doesn't support this API.

0 commit comments

Comments
 (0)