Skip to content

Commit

Permalink
fix(macos): Only include screenshots and view hierarchy for iOS and M…
Browse files Browse the repository at this point in the history
…ac Catalyst builds
  • Loading branch information
krystofwoldrich committed Apr 25, 2023
1 parent 437ade1 commit 39f7fe7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,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

### Dependencies

Expand Down
9 changes: 9 additions & 0 deletions ios/RNSentry.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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<NSData *>* rawScreenshots = [PrivateSentrySDKOnly captureScreenshots];
NSMutableArray *screenshotsArray = [NSMutableArray arrayWithCapacity:[rawScreenshots count]];

Expand All @@ -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];
Expand All @@ -368,8 +373,12 @@ - (void)setEventEnvironmentTag:(SentryEvent *)event
}

resolve(viewHierarchy);
#else
resolve(nil);
#endif
}


RCT_EXPORT_METHOD(setUser:(NSDictionary *)userKeys
otherUserKeys:(NSDictionary *)userDataKeys
)
Expand Down
2 changes: 1 addition & 1 deletion src/js/NativeRNSentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface Spec extends TurboModule {
store: boolean;
},
): Promise<boolean>;
captureScreenshot(): Promise<NativeScreenshot[]>;
captureScreenshot(): Promise<NativeScreenshot[] | undefined | null>;
clearBreadcrumbs(): void;
crash(): void;
closeNativeSdk(): Promise<void>;
Expand Down
11 changes: 8 additions & 3 deletions src/js/wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,14 +467,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;
}
},
Expand Down

0 comments on commit 39f7fe7

Please sign in to comment.