File tree 1 file changed +26
-0
lines changed 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,13 @@ export function getGlobalObject<T>(): T & SentryGlobal {
38
38
: fallbackGlobalObject ) as T & SentryGlobal ;
39
39
}
40
40
41
+ /**
42
+ * Determines if running in react native
43
+ */
44
+ export function isReactNative ( ) : boolean {
45
+ return getGlobalObject < Window > ( ) . navigator ?. product === 'ReactNative' ;
46
+ }
47
+
41
48
/**
42
49
* Extended Window interface that allows for Crypto API usage in IE browsers
43
50
*/
@@ -260,7 +267,26 @@ const performanceFallback: CrossPlatformPerformance = {
260
267
timeOrigin : INITIAL_TIME ,
261
268
} ;
262
269
270
+ /**
271
+ * Performance wrapper for react native as performance.now() has been found to start off with an unusual offset.
272
+ */
273
+ function getReactNativePerformanceWrapper ( ) : CrossPlatformPerformance {
274
+ const INITIAL_OFFSET = performance . now ( ) ;
275
+
276
+ return {
277
+ now ( ) : number {
278
+ return performance . now ( ) - INITIAL_OFFSET ;
279
+ } ,
280
+ timeOrigin : INITIAL_TIME ,
281
+ } ;
282
+ }
283
+
263
284
export const crossPlatformPerformance : CrossPlatformPerformance = ( ( ) : CrossPlatformPerformance => {
285
+ // React Native's performance.now() starts with a gigantic offset, so we need to wrap it.
286
+ if ( isReactNative ( ) ) {
287
+ return getReactNativePerformanceWrapper ( ) ;
288
+ }
289
+
264
290
if ( isNodeEnv ( ) ) {
265
291
try {
266
292
const perfHooks = dynamicRequire ( module , 'perf_hooks' ) as { performance : CrossPlatformPerformance } ;
You can’t perform that action at this time.
0 commit comments