You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/platforms/apple/common/enriching-events/screenshots/index.mdx
+177Lines changed: 177 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,10 +23,187 @@ App hang events won't have a screenshot because the main thread is blocked and S
23
23
24
24
## Enabling Screenshots
25
25
26
+
<Alertlevel="warning">
27
+
28
+
Before enabling screenshots in production, verify your masking configuration to ensure no sensitive data is captured. Our default settings aggressively mask potentially sensitive data, but if you modify these settings or update UI frameworks or system SDKs, you must thoroughly test your application. If you find any masking issues or sensitive data that should be masked but isn't, please [create a GitHub issue](https://github.com/getsentry/sentry-cocoa/issues/new/choose) and avoid deploying to production with screenshots enabled until the issue is resolved.
29
+
30
+
</Alert>
31
+
26
32
Because screenshots may contain <PlatformLinkto="/data-management/sensitive-data/">PII</PlatformLink>, they are an opt-in feature. You can enable screenshots as shown below:
By default, screenshot masking aggressively masks potentially sensitive data to help ensure no sensitive information is captured. You can customize this behavior to fit your application's needs.
39
+
40
+
<Alert>
41
+
42
+
Screenshot masking shares the same runtime APIs as <PlatformLinkto="/session-replay/">Session Replay</PlatformLink> masking (like `SentrySDK.replay.maskView()` and SwiftUI modifiers), but screenshot masking uses separate configuration options via `options.screenshot.*` rather than `options.sessionReplay.*`.
43
+
44
+
</Alert>
45
+
46
+
### Default Masking Behavior
47
+
48
+
By default, screenshots mask all text content and non-bundled images by drawing a black rectangle over them. You can disable this default masking behavior (not recommended for applications with sensitive data):
49
+
50
+
```swift
51
+
options.screenshot.maskAllText=false
52
+
options.screenshot.maskAllImages=false
53
+
```
54
+
55
+
### Mask by View Class
56
+
57
+
You can choose which type of view you want to mask or unmask by using the `maskedViewClasses` or `unmaskedViewClasses` options.
58
+
59
+
By default, Sentry already masks text and image elements from UIKit. Every child of a view that is redacted will also be redacted. The `unmaskedViewClasses` property has precedence over `maskedViewClasses`, meaning if a view class appears in both lists, it will be unmasked.
60
+
61
+
Let's say you have a custom view that you want to mask and a `UILabel` subclass (which normally would be masked) that you don't want to mask. You can set the options like this:
Note that views of classes in `unmaskedViewClasses` will not be redacted, but their children may still be masked.
69
+
70
+
### Mask by View Instance
71
+
72
+
You can also choose to mask or unmask a specific view instance by using the replay API (`SentrySDK.replay`) or view extensions like this:
73
+
74
+
```swift
75
+
SentrySDK.replay.maskView(view: view)
76
+
SentrySDK.replay.unmaskView(view: label)
77
+
```
78
+
79
+
or
80
+
81
+
```swift
82
+
view.sentryReplayMask()
83
+
label.sentryReplayUnmask()
84
+
```
85
+
86
+
<Alert>
87
+
88
+
The runtime masking API for individual view instances may not be available in all Sentry SDK versions. Check your SDK documentation for the latest masking capabilities.
89
+
90
+
</Alert>
91
+
92
+
### SwiftUI Considerations
93
+
94
+
Because of the way SwiftUI is transformed into UIKit, it will often be over-masked. A modifier like `background` uses the same element as an `Image`.
95
+
In order to control the SwiftUI masking process, you need to use the `sentryReplayUnmask` and/or `sentryReplayMask` modifiers.
96
+
97
+
In this example we want to show the message, but not the user name.
98
+
99
+
```swift
100
+
@Bindingvar user: String
101
+
102
+
var body: some View {
103
+
VStack {
104
+
Text("Hello")
105
+
.sentryReplayUnmask()
106
+
Text("\(user)")
107
+
}
108
+
}
109
+
```
110
+
111
+
In this example, we need to unmask the VStack because its background element will be masked by default.
112
+
To hide the username, we need to mask it.
113
+
114
+
```swift
115
+
@Bindingvar user: String
116
+
117
+
var body: some View {
118
+
VStack {
119
+
Text("Hello")
120
+
Text("\(user)")
121
+
.sentryReplayMask()
122
+
}
123
+
.background(.blue)
124
+
.sentryReplayUnmask()
125
+
}
126
+
```
127
+
128
+
## Debugging Screenshot Masking
129
+
130
+
To see how elements are being masked, enable the masking preview from anywhere in your app. It will display an overlay on top of the masked elements. This works on the simulator and on device, as well as within Xcode Preview.
131
+
132
+
```swift
133
+
SentrySDK.replay.showMaskPreview()
134
+
```
135
+
136
+
By default, the overlay will be opaque. To configure the opacity, pass the desired opacity as a parameter:
137
+
138
+
```swift
139
+
SentrySDK.replay.showMaskPreview(0.5) // 0.5 opacity to render the preview semi-transparent
140
+
```
141
+
142
+
Make sure not to accidentally include this in your release build—for example, by wrapping it in a `#if DEBUG` block.
143
+
144
+
```swift
145
+
#if DEBUG
146
+
SentrySDK.replay.showMaskPreview()
147
+
#endif
148
+
```
149
+
150
+
To preview masking during the design phase of your SwiftUI views, use the `sentryReplayPreviewMask` modifier.
151
+
152
+
This view modifier works on the simulator and on device, as well as within Xcode Preview. Therefore we recommend to apply the modifier only in your preview code, to ensure proper masking without affecting the final release build.
153
+
154
+
Note that when you apply this modifier to a view, it will show the masking preview for the entire window containing that view, not just the view itself.
155
+
156
+
```swift
157
+
structContentView_Previews: PreviewProvider {
158
+
staticvar previews: some View {
159
+
ContentView()
160
+
.sentryReplayPreviewMask()
161
+
}
162
+
}
163
+
```
164
+
165
+
## Rendering Options
166
+
167
+
Screenshot rendering can be configured to improve performance. These options control how views are rendered when capturing screenshots.
168
+
169
+
### Enable View Renderer V2
170
+
171
+
Starting with SDK v8.50.0, the up-to-5x-faster view renderer V2 is used by default, reducing the impact of screenshot capture on the main thread and potential frame drops. This reduces the amount of time it takes to render the screenshot on the main thread, reducing interruptions and visual lag. Benchmarks have shown significant improvement of up to 4-5x faster rendering (reducing ~160ms to ~36ms) on older devices.
172
+
173
+
While we recommend the view renderer V2, if you are experiencing issues, you can opt out of using it:
174
+
175
+
```swift
176
+
options.screenshot.enableViewRendererV2=false// Defaults to true
177
+
```
178
+
179
+
### Enable Fast View Rendering
180
+
181
+
Enables up to 5x faster but incomplete view rendering. This flag controls the way the view hierarchy is drawn into a graphics context. By default, the view hierarchy is drawn using `UIView.drawHierarchy(in:afterScreenUpdates:)`, which is the most complete way to render. Enabling this flag switches to render the underlying `CALayer` instead, which is faster but may lead to rendering issues with custom views.
182
+
183
+
Benchmarks have shown up to 5x faster render times (reducing ~160ms to ~30ms) on older devices.
184
+
185
+
<Alertlevel="warning">
186
+
187
+
Rendering the view hierarchy using the `CALayer.render(in:)` method can lead to rendering issues, especially when using custom views. For complete rendering, it is recommended to set this option to `false`. Only enable this if you prefer performance over completeness.
188
+
189
+
</Alert>
190
+
191
+
<Alert>
192
+
193
+
This flag can only be used together with `enableViewRendererV2` for up to 20% faster render times.
194
+
195
+
</Alert>
196
+
197
+
<Alert>
198
+
199
+
This is an experimental feature and is disabled by default. If you notice issues with the experimental view renderer, please report them on [GitHub](https://github.com/getsentry/sentry-cocoa). Eventually, we will mark this feature as stable and remove the experimental flag, but will keep it disabled by default.
200
+
201
+
</Alert>
202
+
203
+
```swift
204
+
options.screenshot.enableFastViewRendering=false// Disabled by default
205
+
```
206
+
30
207
## Viewing Screenshots
31
208
32
209
If one is available, you'll see a thumbnail of the screenshot when you click on a specific issue from the [**Issues**](https://demo.sentry.io/issues/) page.
0 commit comments