Skip to content

Commit

Permalink
Add beforeScreenshot callback (#3715)
Browse files Browse the repository at this point in the history
  • Loading branch information
doronpr authored Apr 10, 2024
1 parent 316cfc6 commit 5a22220
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion src/js/integrations/screenshot.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -41,9 +43,11 @@ export class Screenshot implements Integration {
* @inheritDoc
*/
public setupOnce(addGlobalEventProcessor: (e: EventProcessor) => void): void {
const options = getClient<ReactNativeClient>()?.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;
}

Expand Down
9 changes: 8 additions & 1 deletion src/js/options.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 5a22220

Please sign in to comment.