Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
beforeScreenshot
  • Loading branch information
doronpr committed Mar 27, 2024
commit 01e353f8586ab69c0701d3375c9eea0fa3b2a94f
10 changes: 5 additions & 5 deletions 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 All @@ -16,10 +18,6 @@ export class Screenshot implements Integration {
*/
public name: string = Screenshot.id;

protected shouldAttachScreenshot(_event: Event, _hint: EventHint): boolean {
return true;
}

/**
* If enabled attaches a screenshot to the event hint.
*
Expand All @@ -45,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 || !this.shouldAttachScreenshot(event, hint)) {
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