Skip to content

test(replay): Test that blocking elements works as expected #7201

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

Merged
merged 4 commits into from
Feb 20, 2023
Merged
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
1 change: 1 addition & 0 deletions packages/integration-tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test-results
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a .gitginore to ensure this is not accidentally checked in.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, also saw this folder floating around recently

20 changes: 20 additions & 0 deletions packages/integration-tests/suites/replay/privacyBlock/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as Sentry from '@sentry/browser';
import { Replay } from '@sentry/replay';

window.Sentry = Sentry;
window.Replay = new Replay({
flushMinDelay: 200,
flushMaxDelay: 200,
useCompression: false,
blockAllMedia: false,
block: ['link[rel="icon"]', 'video', '.nested-hide'],
});

Sentry.init({
dsn: 'https://[email protected]/1337',
sampleRate: 0,
replaysSessionSampleRate: 1.0,
replaysOnErrorSampleRate: 0.0,

integrations: [window.Replay],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="icon" type="image/png" href="file://assets/icon/favicon.png"/>
</head>
<body>
<button aria-label="Click me" onclick="console.log('Test log')">Click me</button>
<div>This should be masked by default</div>
<div data-sentry-unmask>This should be unmasked due to data attribute</div>
<input placeholder="Placeholder should be masked" />
<div title="Title should be masked">Title should be masked</div>
<svg style="width:200px;height:200px" viewBox="0 0 80 80"><path d=""/><area /><rect /></svg>
<svg style="width:200px;height:200px" viewBox="0 0 80 80" data-sentry-unblock><path d=""/><area /><rect /></svg>
<img style="width:100px;height:100px" src="file:///none.png" />
<img data-sentry-unblock style="width:100px;height:100px" src="file:///none.png" />
<video style="width:30px;height:30px"><source src="file://foo.mp4" /></video>
<div class="nested-hide">
<div>This should be hidden.</div>
</div>
</body>
</html>
35 changes: 35 additions & 0 deletions packages/integration-tests/suites/replay/privacyBlock/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { expect } from '@playwright/test';

import { sentryTest } from '../../../utils/fixtures';
import {
getFullRecordingSnapshots,
normalize,
shouldSkipReplayTest,
waitForReplayRequest,
} from '../../../utils/replayHelpers';

sentryTest('should allow to manually block elements', async ({ getLocalTestPath, page }) => {
if (shouldSkipReplayTest()) {
sentryTest.skip();
}

const reqPromise0 = waitForReplayRequest(page, 0);

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 getLocalTestPath({ testDir: __dirname });

await page.goto(url);
const snapshots = getFullRecordingSnapshots(await reqPromise0);
expect(snapshots.length).toEqual(1);

const stringifiedSnapshot = normalize(snapshots[0], { normalizeNumberAttributes: ['rr_width', 'rr_height'] });

expect(stringifiedSnapshot).toMatchSnapshot('privacy.json');
});
Loading