Repository navigation
feat(replay-canvas): Support Trusted Types for the canvas worker #26893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
+79
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
dev-packages/browser-integration-tests/suites/replay/canvas/trustedTypes/init.js
This file contains hidden or 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,17 @@ | ||
| import * as Sentry from '@sentry/browser'; | ||
|
|
||
| window.Sentry = Sentry; | ||
| window.Replay = Sentry.replayIntegration({ | ||
| flushMinDelay: 50, | ||
| flushMaxDelay: 50, | ||
| minReplayDuration: 0, | ||
| }); | ||
|
|
||
|
Check notice on line 9 in dev-packages/browser-integration-tests/suites/replay/canvas/trustedTypes/init.js
|
||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| sampleRate: 0, | ||
| replaysSessionSampleRate: 1.0, | ||
| replaysOnErrorSampleRate: 0.0, | ||
|
|
||
| integrations: [window.Replay, Sentry.replayCanvasIntegration()], | ||
| }); | ||
25 changes: 25 additions & 0 deletions
25
dev-packages/browser-integration-tests/suites/replay/canvas/trustedTypes/template.html
This file contains hidden or 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,25 @@ | ||
| <!doctype html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8" /> | ||
| <meta http-equiv="Content-Security-Policy" content="require-trusted-types-for 'script'; trusted-types sentry-sdk" /> | ||
| </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) { | ||
| 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> |
31 changes: 31 additions & 0 deletions
31
dev-packages/browser-integration-tests/suites/replay/canvas/trustedTypes/test.ts
This file contains hidden or 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,31 @@ | ||
| import { expect } from '@playwright/test'; | ||
| import { IncrementalSource } from '@sentry/rrweb'; | ||
| import { sentryTest } from '../../../../utils/fixtures'; | ||
| import { collectReplayRequests, shouldSkipReplayTest, waitForReplayRequest } from '../../../../utils/replayHelpers'; | ||
|
|
||
| sentryTest('records canvas on pages that enforce Trusted Types', async ({ getLocalTestUrl, page }) => { | ||
| if (shouldSkipReplayTest() || (process.env.PW_BUNDLE || '').startsWith('bundle')) { | ||
| sentryTest.skip(); | ||
| } | ||
|
|
||
| await page.addInitScript(() => { | ||
| (window as any)._violations = []; | ||
| document.addEventListener('securitypolicyviolation', event => { | ||
| (window as any)._violations.push(`${event.violatedDirective}: ${event.sample}`); | ||
| }); | ||
| }); | ||
|
|
||
| const reqPromise0 = waitForReplayRequest(page, 0); | ||
|
|
||
| await page.goto(await getLocalTestUrl({ testDir: __dirname })); | ||
| await reqPromise0; | ||
|
|
||
| const canvasRequestsPromise = collectReplayRequests(page, snapshots => | ||
| snapshots.some(({ data }) => 'source' in data && data.source === IncrementalSource.CanvasMutation), | ||
| ); | ||
|
|
||
| await page.click('#draw'); | ||
| await canvasRequestsPromise; | ||
|
|
||
| expect(await page.evaluate(() => (window as any)._violations)).toEqual([]); | ||
| }); | ||
This file contains hidden or 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 hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trusted Types canvas test runs on WebKit
Low Severity
This test waits until a
CanvasMutationsnapshot arrives, but unlike the existingrecordsandmanualSnapshotcanvas tests it doesn't skipwebkit. If WebKit never emits canvas mutation snapshots (likely the reason those tests skip it),collectReplayRequestswill hang until timeout and the test will fail or flake in the WebKit project.Additional Locations (1)
dev-packages/browser-integration-tests/suites/replay/canvas/trustedTypes/test.ts#L22-L28Triggered by project rule: PR Review Guidelines for Cursor Bot
Reviewed by Cursor Bugbot for commit 30a6312. Configure here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It passes on WebKit locally and in CI it only runs in Chromium because the WebKit job uses a CDN bundle and the test skips bundles