Screenshots

When a user experiences an error, an exception or a crash, Sentry provides the ability to take a screenshot and include it as an attachment.

This feature only applies to SDKs with a user interface, such as the ones for mobile and desktop applications. In some environments like native iOS, taking a screenshot requires the UI thread and in the event of a crash, that might not be available. Another example where a screenshot might not be available is when the event happens before the screen starts to load. So inherently, this feature is a best effort solution.

Enabling Screenshots

Screenshots may contain PII and is an opt-in feature. You can enable it as shown below:

AndroidManifest.xml
Copied
<application>
  <meta-data android:name="io.sentry.attach-screenshot" android:value="true" />
</application>

Customize Screenshot Capturing

Because capturing screenshots can be a resource-intensive operation on Android, it's limited to one screenshot every 2 seconds using a debouncing mechanism. This behavior can be overruled if you supply a BeforeCaptureCallback for screenshots in the SentryAndroidOptions.

The BeforeCaptureCallback also allows you to customize the behavior based on event data, so you can decide when to capture a screenshot and when not to. For example, you can decide to only capture screenshots of crashed and fatal events:

Copied
import io.sentry.android.core.SentryAndroid;

SentryAndroid.init(this, options -> {
    options.setBeforeScreenshotCaptureCallback((event, hint, debounce) -> {
        // always capture crashed events
        if (event.isCrashed()) {
            return true;
        }

        // if debounce is active, skip capturing
        if (debounce) {
            return false;
        } else {
            // also capture fatal events
            return event.getLevel() == SentryLevel.FATAL;
        }
    });
});

Viewing Screenshots

A thumbnail of the screenshot shows up at the top of the Issue Details page:

Screenshot Thumbnail

Additionally, screenshots appear in the "Attachments" tab, where you can view all attachments, as well as associated events. Click the event ID to open the Issue Details page of that specific event.

Screenshots List Example

You can see an overview of all the screenshots associated with the events in your issue by clicking "Screenshots" in the "Attachments" tab.

Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").