Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

View check run for this annotation

@sentry/warden / warden: code-review

Trusted Types canvas test times out on WebKit in the unbundled all-browser run

When `pnpm test:all` runs without `PW_BUNDLE`, the WebKit project reaches this test and waits for a CanvasMutation response; unlike the sibling canvas tests, it does not skip WebKit, so the wait times out.
Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
sampleRate: 0,
replaysSessionSampleRate: 1.0,
replaysOnErrorSampleRate: 0.0,

integrations: [window.Replay, Sentry.replayCanvasIntegration()],
});
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>
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();
}

Copy link
Copy Markdown

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 CanvasMutation snapshot arrives, but unlike the existing records and manualSnapshot canvas tests it doesn't skip webkit. If WebKit never emits canvas mutation snapshots (likely the reason those tests skip it), collectReplayRequests will hang until timeout and the test will fail or flake in the WebKit project.

Additional Locations (1)
Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit 30a6312. Configure here.

Copy link
Copy Markdown
Member Author

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


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([]);
});
1 change: 1 addition & 0 deletions packages/replay-canvas/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"@sentry/rrweb": "2.47.0"
},
"dependencies": {
"@sentry/browser-utils": "11.19.0",
"@sentry/replay": "11.19.0",
"@sentry/core": "11.19.0"
},
Expand Down
2 changes: 2 additions & 0 deletions packages/replay-canvas/src/canvas.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getTrustedScriptURL } from '@sentry/browser-utils';
import type { Integration, IntegrationFn } from '@sentry/core';
import { defineIntegration } from '@sentry/core';
import type { CanvasManagerInterface, CanvasManagerOptions } from '@sentry/replay';
Expand Down Expand Up @@ -94,6 +95,7 @@ export const _replayCanvasIntegration = ((options: Partial<ReplayCanvasOptions>
...getCanvasManagerOptions,
enableManualSnapshot,
maxCanvasSize,
getTrustedScriptURL,
errorHandler: (err: unknown) => {
try {
if (typeof err === 'object') {
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading