From 92992580b3d8379a8b00e219fae5a5b951745e4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kry=C5=A1tof=20Wold=C5=99ich?= <31292499+krystofwoldrich@users.noreply.github.com> Date: Tue, 25 Apr 2023 14:18:02 +0200 Subject: [PATCH] fix(macos): Only include screenshots and view hierarchy for iOS and Mac Catalyst builds (#3007) --- CHANGELOG.md | 1 + ios/RNSentry.mm | 9 +++++++++ src/js/NativeRNSentry.ts | 2 +- src/js/wrapper.ts | 11 ++++++++--- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a8288d19e..f227066e0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - Allow disabling native on RNNA ([#2978](https://github.com/getsentry/sentry-react-native/pull/2978)) - iOS Autolinking for RN 0.68 and older ([#2980](https://github.com/getsentry/sentry-react-native/pull/2980)) +- Only include Screenshots and View Hierarchy for iOS and Mac Catalyst builds ([#3007](https://github.com/getsentry/sentry-react-native/pull/3007)) - Breadcrumbs from Native SDKs are created with timestamps in seconds ([#2997](https://github.com/getsentry/sentry-react-native/pull/2997)) - `addBreadcrumb` converts converts non object data to `{ value: data }` ([#2997](https://github.com/getsentry/sentry-react-native/pull/2997)) diff --git a/ios/RNSentry.mm b/ios/RNSentry.mm index d346425007..0f6f631e13 100644 --- a/ios/RNSentry.mm +++ b/ios/RNSentry.mm @@ -330,6 +330,7 @@ - (void)setEventEnvironmentTag:(SentryEvent *)event RCT_EXPORT_METHOD(captureScreenshot: (RCTPromiseResolveBlock)resolve rejecter: (RCTPromiseRejectBlock)reject) { +#if TARGET_OS_IPHONE || TARGET_OS_MACCATALYST NSArray* rawScreenshots = [PrivateSentrySDKOnly captureScreenshots]; NSMutableArray *screenshotsArray = [NSMutableArray arrayWithCapacity:[rawScreenshots count]]; @@ -354,11 +355,15 @@ - (void)setEventEnvironmentTag:(SentryEvent *)event } resolve(screenshotsArray); +#else + resolve(nil); +#endif } RCT_EXPORT_METHOD(fetchViewHierarchy: (RCTPromiseResolveBlock)resolve rejecter: (RCTPromiseRejectBlock)reject) { +#if TARGET_OS_IPHONE || TARGET_OS_MACCATALYST NSData * rawViewHierarchy = [PrivateSentrySDKOnly captureViewHierarchy]; NSMutableArray *viewHierarchy = [NSMutableArray arrayWithCapacity:rawViewHierarchy.length]; @@ -368,8 +373,12 @@ - (void)setEventEnvironmentTag:(SentryEvent *)event } resolve(viewHierarchy); +#else + resolve(nil); +#endif } + RCT_EXPORT_METHOD(setUser:(NSDictionary *)userKeys otherUserKeys:(NSDictionary *)userDataKeys ) diff --git a/src/js/NativeRNSentry.ts b/src/js/NativeRNSentry.ts index d0208ed7f6..4c2f8bb7ab 100644 --- a/src/js/NativeRNSentry.ts +++ b/src/js/NativeRNSentry.ts @@ -13,7 +13,7 @@ export interface Spec extends TurboModule { store: boolean; }, ): Promise; - captureScreenshot(): Promise; + captureScreenshot(): Promise; clearBreadcrumbs(): void; crash(): void; closeNativeSdk(): Promise; diff --git a/src/js/wrapper.ts b/src/js/wrapper.ts index 538b5ba038..4b494bf6d0 100644 --- a/src/js/wrapper.ts +++ b/src/js/wrapper.ts @@ -466,14 +466,19 @@ export const NATIVE: SentryNativeWrapper = { return null; } + let raw: NativeScreenshot[] | null | undefined; try { - const raw = await RNSentry.captureScreenshot(); + raw = await RNSentry.captureScreenshot(); + } catch (e) { + logger.warn('Failed to capture screenshot', e); + } + + if (raw) { return raw.map((item: NativeScreenshot) => ({ ...item, data: new Uint8Array(item.data), })); - } catch (e) { - logger.warn('Failed to capture screenshot', e); + } else { return null; } },