Skip to content

Commit ba3bdbb

Browse files
brustolinphilprimekahest
authored
feat(apple): Debug session replay masking (#12517)
Co-authored-by: Philip Niedertscheider <phil.niedertscheider@sentry.io> Co-authored-by: Karl Heinz Struggl <kahest@users.noreply.github.com>
1 parent c341c76 commit ba3bdbb

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

docs/platforms/apple/guides/ios/session-replay/customredact.mdx

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ If you choose to use custom masking in your Session Replays, you may accidentall
1414

1515
By default, our Session Replay SDK masks all text content, images, and user input. This helps ensure that no sensitive data will be exposed. You can also manually choose which parts of your app's data you want to mask by using the different options listed below.
1616

17-
1817
## Mask by View Class
1918

2019
You can choose which type of view you want to mask or unmask by using the `maskedViewClasses` or `unmaskedViewClasses` options.
@@ -34,6 +33,7 @@ You can also choose to mask or unmask a specific view instance by using the repl
3433
SentrySDK.replay.maskView(view: view)
3534
SentrySDK.replay.unmaskView(view: label)
3635
```
36+
3737
or
3838

3939
```swift
@@ -44,9 +44,10 @@ or
4444
## SwiftUI
4545

4646
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`.
47-
In order to control the SwiftUI masking process, you need to use the `sentryReplayUnmask` and/or `sentryReplayMask` modifiers.
47+
In order to control the SwiftUI masking process, you need to use the `sentryReplayUnmask` and/or `sentryReplayMask` modifiers.
4848

4949
In this example we want to show the message, but not the user name.
50+
5051
```swift
5152
@Binding var user: String
5253

@@ -72,6 +73,43 @@ To hide the username, we need to mask it.
7273
.sentryReplayMask()
7374
}
7475
.background(.blue)
75-
.sentryReplayUnmask()
76+
.sentryReplayUnmask()
77+
}
78+
```
79+
80+
## Debugging Session Replay masking
81+
82+
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.
83+
84+
```swift
85+
SentrySDK.replay.showMaskPreview()
86+
```
87+
88+
By default, the overlay will be opaque. To configure the opacity, pass the desired opacity as a parameter:
89+
90+
```swift
91+
SentrySDK.replay.showMaskPreview(0.5) // 0.5 opacity to render the preview semi-transparent
92+
```
93+
94+
Make sure not accidentally include this in your release build by e.g. wrapping it in a `#if DEBUG` block.
95+
96+
```swift
97+
#if DEBUG
98+
SentrySDK.replay.showMaskPreview()
99+
#endif
100+
```
101+
102+
To preview masking during the design phase of your SwiftUI views, use the `sentryReplayPreviewMask` modifier.
103+
104+
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.
105+
106+
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.
107+
108+
```swift
109+
struct ContentView_Previews: PreviewProvider {
110+
static var previews: some View {
111+
ContentView()
112+
.sentryReplayPreviewMask()
76113
}
114+
}
77115
```

0 commit comments

Comments
 (0)