Skip to content

Commit 93323cb

Browse files
andreiborzaclaudeinventarSarah
authored
feat(replay): Document skipRequestAnimationFrame option for WebGPU canvas snapshots (#16011)
Adds documentation for the `skipRequestAnimationFrame` option when using manual canvas snapshots with WebGPU. WebGPU textures expire after the current task completes, so deferring snapshot capture to the next animation frame results in an empty canvas. This option captures immediately after rendering. Sources: - https://gpuweb.github.io/gpuweb/explainer/ - gpuweb/gpuweb#2743 - gpuweb/gpuweb#3295 Related: getsentry/sentry-javascript#18804 --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Sarah Mischinger <sarah@codingwriter.com>
1 parent ff82e52 commit 93323cb

1 file changed

Lines changed: 32 additions & 3 deletions

File tree

  • docs/platforms/javascript/common/session-replay

docs/platforms/javascript/common/session-replay/index.mdx

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,36 @@ function paint() {
100100
Sentry.getClient().getIntegrationByName("ReplayCanvas").snapshot(canvasRef);
101101
}
102102
```
103+
104+
#### WebGPU Canvases
105+
106+
WebGPU works differently from WebGL in how it manages the lifetime of rendered frames. The canvas texture returned by `getCurrentTexture()` is only valid until the current task completes – after that, the texture expires, and its contents are no longer accessible. This means that by default, when `snapshot()` defers capture to the next animation frame, it will capture an empty or invalid canvas. There are two steps to capturing WebGPU canvases:
107+
108+
**Step 1.**
109+
Enable manual snapshotting when initializing the `ReplayCanvas` integration.
110+
111+
```javascript
112+
Sentry.replayCanvasIntegration({
113+
// Enabling the following will ensure your canvas elements are not forced
114+
// into `preserveDrawingBuffer`.
115+
enableManualSnapshot: true,
116+
});
117+
```
118+
119+
**Step 2.**
120+
Call the `snapshot()` method inside your application's paint loop with `skipRequestAnimationFrame: true` to capture the snapshot immediately:
121+
122+
```javascript
123+
function paint() {
124+
const canvasRef = document.querySelector("#my-canvas");
125+
const canvasIntegration = Sentry.getClient().getIntegrationByName("ReplayCanvas");
126+
127+
// ... your WebGPU rendering commands ...
128+
129+
// Capture immediately after rendering - required for WebGPU
130+
canvasIntegration.snapshot(canvasRef, { skipRequestAnimationFrame: true });
131+
}
132+
```
103133
</PlatformSection>
104134

105135
### Content Security Policy (CSP)
@@ -161,11 +191,11 @@ Sampling allows you to control how much of your website's traffic will result in
161191
```javascript {5-6} {filename:instrumentation-client.ts}
162192
Sentry.init({
163193
// ... other configuration
164-
194+
165195
// Session Replay sampling rates
166196
replaysSessionSampleRate: 0.1, // Capture 10% of all sessions
167197
replaysOnErrorSampleRate: 1.0, // Capture 100% of error sessions
168-
198+
169199
// For development/testing, you can set replaysSessionSampleRate to 1.0
170200
// to capture all sessions for complete visibility
171201
});
@@ -204,4 +234,3 @@ Once testing is complete, **we recommend lowering this value in production**. We
204234
## Next Steps
205235

206236
<PageGrid />
207-

0 commit comments

Comments
 (0)