Skip to content

Commit 5a22220

Browse files
authored
Add beforeScreenshot callback (#3715)
1 parent 316cfc6 commit 5a22220

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Features
66

77
- Add `getDefaultConfig` option to `getSentryExpoConfig` ([#3690](https://github.com/getsentry/sentry-react-native/pull/3690))
8+
- Add `beforeScreenshoot` option to `ReactNativeOptions` ([#3715](https://github.com/getsentry/sentry-react-native/pull/3715))
89

910
### Fixes
1011

src/js/integrations/screenshot.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import { getClient } from '@sentry/core';
12
import type { Event, EventHint, EventProcessor, Integration } from '@sentry/types';
23
import { resolvedSyncPromise } from '@sentry/utils';
34

5+
import type { ReactNativeClient } from '../client';
46
import type { Screenshot as ScreenshotAttachment } from '../wrapper';
57
import { NATIVE } from '../wrapper';
68

@@ -41,9 +43,11 @@ export class Screenshot implements Integration {
4143
* @inheritDoc
4244
*/
4345
public setupOnce(addGlobalEventProcessor: (e: EventProcessor) => void): void {
46+
const options = getClient<ReactNativeClient>()?.getOptions();
47+
4448
addGlobalEventProcessor(async (event: Event, hint: EventHint) => {
4549
const hasException = event.exception && event.exception.values && event.exception.values.length > 0;
46-
if (!hasException) {
50+
if (!hasException || options?.beforeScreenshot?.(event, hint) === false) {
4751
return event;
4852
}
4953

src/js/options.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { BrowserTransportOptions } from '@sentry/browser/types/transports/types';
22
import type { ProfilerProps } from '@sentry/react/types/profiler';
3-
import type { CaptureContext, ClientOptions, Options } from '@sentry/types';
3+
import type { CaptureContext, ClientOptions, Event, EventHint, Options } from '@sentry/types';
44
import { Platform } from 'react-native';
55

66
import type { TouchEventBoundaryProps } from './touchevents';
@@ -180,6 +180,13 @@ export interface BaseReactNativeOptions {
180180
* @default "http://localhost:8969/stream"
181181
*/
182182
spotlightSidecarUrl?: string;
183+
184+
/**
185+
* Sets a callback which is executed before capturing screenshots. Only
186+
* relevant if `attachScreenshot` is set to true. When false is returned
187+
* from the function, no screenshot will be attached.
188+
*/
189+
beforeScreenshot?: (event: Event, hint: EventHint) => boolean;
183190
}
184191

185192
export interface ReactNativeTransportOptions extends BrowserTransportOptions {

0 commit comments

Comments
 (0)