-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(replays): Add snapshot function to replay canvas integration (#1…
…0066) Adds a snapshot function that allows the user to manually snapshot canvas for gl/3d contexts. Manual snapshot will take a snapshot of the canvas element passed in or all canvas in the window if nothing is passed in. To manually snapshot: 1. Add ReplayCanvas to your Sentry integrations: `new Sentry.ReplayCanvas({ enableManualSnapshot:true })` 2. Add snapshot function, eg. `Sentry.getClient().getIntegrationByName('ReplayCanvas').snapshot();` into your render/repaint Closes getsentry/team-replay#308 --------- Co-authored-by: Francesco Novy <francesco.novy@sentry.io> Co-authored-by: Billy Vong <billyvg@users.noreply.github.com>
- Loading branch information
1 parent
0477453
commit 583d720
Showing
10 changed files
with
149 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
dev-packages/browser-integration-tests/suites/replay/canvas/manualSnapshot/init.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
window.Replay = new Sentry.Replay({ | ||
flushMinDelay: 50, | ||
flushMaxDelay: 50, | ||
minReplayDuration: 0, | ||
}); | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
sampleRate: 0, | ||
replaysSessionSampleRate: 1.0, | ||
replaysOnErrorSampleRate: 0.0, | ||
debug: true, | ||
|
||
integrations: [window.Replay, new Sentry.ReplayCanvas({ enableManualSnapshot: true })], | ||
}); |
26 changes: 26 additions & 0 deletions
26
dev-packages/browser-integration-tests/suites/replay/canvas/manualSnapshot/template.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
</head> | ||
<body> | ||
<canvas id="canvas" width="150" height="150"></canvas> | ||
<button id="draw">Draw</button> | ||
</body> | ||
|
||
|
||
<script> | ||
function draw() { | ||
const canvas = document.getElementById("canvas"); | ||
if (canvas.getContext) { | ||
console.log('has canvas') | ||
const ctx = canvas.getContext("2d"); | ||
|
||
ctx.fillRect(25, 25, 100, 100); | ||
ctx.clearRect(45, 45, 60, 60); | ||
ctx.strokeRect(50, 50, 50, 50); | ||
} | ||
} | ||
document.getElementById('draw').addEventListener('click', draw); | ||
</script> | ||
</html> |
79 changes: 79 additions & 0 deletions
79
dev-packages/browser-integration-tests/suites/replay/canvas/manualSnapshot/test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { expect } from '@playwright/test'; | ||
|
||
import { sentryTest } from '../../../../utils/fixtures'; | ||
import { getReplayRecordingContent, shouldSkipReplayTest, waitForReplayRequest } from '../../../../utils/replayHelpers'; | ||
|
||
sentryTest('can manually snapshot canvas', async ({ getLocalTestUrl, page, browserName }) => { | ||
if (shouldSkipReplayTest() || browserName === 'webkit' || (process.env.PW_BUNDLE || '').startsWith('bundle')) { | ||
sentryTest.skip(); | ||
} | ||
|
||
const reqPromise0 = waitForReplayRequest(page, 0); | ||
const reqPromise1 = waitForReplayRequest(page, 1); | ||
const reqPromise2 = waitForReplayRequest(page, 2); | ||
const reqPromise3 = waitForReplayRequest(page, 3); | ||
|
||
await page.route('https://dsn.ingest.sentry.io/**/*', route => { | ||
return route.fulfill({ | ||
status: 200, | ||
contentType: 'application/json', | ||
body: JSON.stringify({ id: 'test-id' }), | ||
}); | ||
}); | ||
|
||
const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
||
await page.goto(url); | ||
await reqPromise0; | ||
await Promise.all([page.click('#draw'), reqPromise1]); | ||
|
||
const { incrementalSnapshots } = getReplayRecordingContent(await reqPromise2); | ||
expect(incrementalSnapshots).toEqual([]); | ||
|
||
await page.evaluate(() => { | ||
(window as any).Sentry.getClient().getIntegrationById('ReplayCanvas').snapshot(); | ||
}); | ||
|
||
const { incrementalSnapshots: incrementalSnapshotsManual } = getReplayRecordingContent(await reqPromise3); | ||
expect(incrementalSnapshotsManual).toEqual( | ||
expect.arrayContaining([ | ||
{ | ||
data: { | ||
commands: [ | ||
{ | ||
args: [0, 0, 150, 150], | ||
property: 'clearRect', | ||
}, | ||
{ | ||
args: [ | ||
{ | ||
args: [ | ||
{ | ||
data: [ | ||
{ | ||
base64: expect.any(String), | ||
rr_type: 'ArrayBuffer', | ||
}, | ||
], | ||
rr_type: 'Blob', | ||
type: 'image/webp', | ||
}, | ||
], | ||
rr_type: 'ImageBitmap', | ||
}, | ||
0, | ||
0, | ||
], | ||
property: 'drawImage', | ||
}, | ||
], | ||
id: 9, | ||
source: 9, | ||
type: 0, | ||
}, | ||
timestamp: 0, | ||
type: 3, | ||
}, | ||
]), | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters