Skip to content

Commit 843f68e

Browse files
billyvgc298lee
authored andcommitted
test(browser-integration): Add test for Replay canvas recording (#10079)
Adds a test to ensure that Replay canvas recording works.
1 parent 2d007ca commit 843f68e

File tree

4 files changed

+130
-0
lines changed

4 files changed

+130
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { getCanvasManager } from '@sentry-internal/rrweb';
2+
import * as Sentry from '@sentry/browser';
3+
4+
window.Sentry = Sentry;
5+
window.Replay = new Sentry.Replay({
6+
flushMinDelay: 50,
7+
flushMaxDelay: 50,
8+
minReplayDuration: 0,
9+
_experiments: {
10+
canvas: {
11+
manager: getCanvasManager,
12+
},
13+
},
14+
});
15+
16+
Sentry.init({
17+
dsn: 'https://[email protected]/1337',
18+
sampleRate: 0,
19+
replaysSessionSampleRate: 1.0,
20+
replaysOnErrorSampleRate: 0.0,
21+
debug: true,
22+
23+
integrations: [window.Replay],
24+
});
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
</head>
6+
<body>
7+
<canvas id="canvas" width="150" height="150"></canvas>
8+
<button id="draw">Draw</button>
9+
</body>
10+
11+
12+
<script>
13+
function draw() {
14+
const canvas = document.getElementById("canvas");
15+
if (canvas.getContext) {
16+
console.log('has canvas')
17+
const ctx = canvas.getContext("2d");
18+
19+
ctx.fillRect(25, 25, 100, 100);
20+
ctx.clearRect(45, 45, 60, 60);
21+
ctx.strokeRect(50, 50, 50, 50);
22+
}
23+
}
24+
document.getElementById('draw').addEventListener('click', draw);
25+
</script>
26+
</html>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { expect } from '@playwright/test';
2+
3+
import { sentryTest } from '../../../../utils/fixtures';
4+
import { getReplayRecordingContent, shouldSkipReplayTest, waitForReplayRequest } from '../../../../utils/replayHelpers';
5+
6+
sentryTest('can record canvas', async ({ getLocalTestUrl, page, browserName }) => {
7+
if (shouldSkipReplayTest() || browserName === 'webkit') {
8+
sentryTest.skip();
9+
}
10+
11+
const reqPromise0 = waitForReplayRequest(page, 0);
12+
const reqPromise1 = waitForReplayRequest(page, 1);
13+
const reqPromise2 = waitForReplayRequest(page, 2);
14+
15+
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
16+
return route.fulfill({
17+
status: 200,
18+
contentType: 'application/json',
19+
body: JSON.stringify({ id: 'test-id' }),
20+
});
21+
});
22+
23+
const url = await getLocalTestUrl({ testDir: __dirname });
24+
25+
await page.goto(url);
26+
await reqPromise0;
27+
await Promise.all([page.click('#draw'), reqPromise1]);
28+
29+
const { incrementalSnapshots } = getReplayRecordingContent(await reqPromise2);
30+
expect(incrementalSnapshots).toEqual(
31+
expect.arrayContaining([
32+
{
33+
data: {
34+
commands: [
35+
{
36+
args: [0, 0, 150, 150],
37+
property: 'clearRect',
38+
},
39+
{
40+
args: [
41+
{
42+
args: [
43+
{
44+
data: [
45+
{
46+
base64: expect.any(String),
47+
rr_type: 'ArrayBuffer',
48+
},
49+
],
50+
rr_type: 'Blob',
51+
type: 'image/webp',
52+
},
53+
],
54+
rr_type: 'ImageBitmap',
55+
},
56+
0,
57+
0,
58+
],
59+
property: 'drawImage',
60+
},
61+
],
62+
id: 9,
63+
source: 9,
64+
type: 0,
65+
},
66+
timestamp: 0,
67+
type: 3,
68+
},
69+
]),
70+
);
71+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
</head>
6+
<body>
7+
<button onclick="console.log('Test log')">Click me</button>
8+
</body>
9+
</html>

0 commit comments

Comments
 (0)