diff --git a/CHANGELOG.md b/CHANGELOG.md index 536ecdba4..4b7ff032e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Features - Add `getDefaultConfig` option to `getSentryExpoConfig` ([#3690](https://github.com/getsentry/sentry-react-native/pull/3690)) +- Add `beforeScreenshoot` option to `ReactNativeOptions` ([#3715](https://github.com/getsentry/sentry-react-native/pull/3715)) ### Fixes diff --git a/src/js/integrations/screenshot.ts b/src/js/integrations/screenshot.ts index 699916e01..a52d15276 100644 --- a/src/js/integrations/screenshot.ts +++ b/src/js/integrations/screenshot.ts @@ -1,6 +1,8 @@ +import { getClient } from '@sentry/core'; import type { Event, EventHint, EventProcessor, Integration } from '@sentry/types'; import { resolvedSyncPromise } from '@sentry/utils'; +import type { ReactNativeClient } from '../client'; import type { Screenshot as ScreenshotAttachment } from '../wrapper'; import { NATIVE } from '../wrapper'; @@ -41,9 +43,11 @@ export class Screenshot implements Integration { * @inheritDoc */ public setupOnce(addGlobalEventProcessor: (e: EventProcessor) => void): void { + const options = getClient()?.getOptions(); + addGlobalEventProcessor(async (event: Event, hint: EventHint) => { const hasException = event.exception && event.exception.values && event.exception.values.length > 0; - if (!hasException) { + if (!hasException || options?.beforeScreenshot?.(event, hint) === false) { return event; } diff --git a/src/js/options.ts b/src/js/options.ts index d12db7991..69a0fb5b2 100644 --- a/src/js/options.ts +++ b/src/js/options.ts @@ -1,6 +1,6 @@ import type { BrowserTransportOptions } from '@sentry/browser/types/transports/types'; import type { ProfilerProps } from '@sentry/react/types/profiler'; -import type { CaptureContext, ClientOptions, Options } from '@sentry/types'; +import type { CaptureContext, ClientOptions, Event, EventHint, Options } from '@sentry/types'; import { Platform } from 'react-native'; import type { TouchEventBoundaryProps } from './touchevents'; @@ -180,6 +180,13 @@ export interface BaseReactNativeOptions { * @default "http://localhost:8969/stream" */ spotlightSidecarUrl?: string; + + /** + * Sets a callback which is executed before capturing screenshots. Only + * relevant if `attachScreenshot` is set to true. When false is returned + * from the function, no screenshot will be attached. + */ + beforeScreenshot?: (event: Event, hint: EventHint) => boolean; } export interface ReactNativeTransportOptions extends BrowserTransportOptions {