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,10 @@
import * as Sentry from '@sentry/browser';
// Import this separately so that generatePlugin can handle it for CDN scenarios
import { feedbackIntegration } from '@sentry/browser';

window.Sentry = Sentry;

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
integrations: [feedbackIntegration({ enableScreenshot: true })],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
window.__TRUSTED_TYPES_VIOLATIONS__ = [];
document.addEventListener('securitypolicyviolation', e => {
window.__TRUSTED_TYPES_VIOLATIONS__.push(`${e.violatedDirective}: ${e.sample}`);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Security-Policy" content="require-trusted-types-for 'script'" />
</head>
<body></body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { expect } from '@playwright/test';
import { sentryTest } from '../../../utils/fixtures';
import { envelopeRequestParser, getEnvelopeType, testingCdnBundle } from '../../../utils/helpers';

sentryTest.beforeEach(() => {
// CDN bundles lazy load the feedback modal through a `script.src` sink, which needs a Trusted Types policy.
sentryTest.skip(testingCdnBundle());
});

sentryTest('renders the feedback form without Trusted Types violations', async ({ getLocalTestUrl, page }) => {
const feedbackRequestPromise = page.waitForRequest(req => {
try {
return getEnvelopeType(req) === 'feedback';
} catch {
return false;
}
});

await page.goto(await getLocalTestUrl({ testDir: __dirname }));
await page.getByText('Report a Bug').click();

await expect(page.locator('.brand-link svg')).toBeVisible();

await page.locator('[name="message"]').fill('my example feedback');
await page.locator('[data-sentry-feedback] .btn--primary').click();

expect(envelopeRequestParser(await feedbackRequestPromise).contexts?.feedback?.message).toBe('my example feedback');
await expect(page.locator('.success__icon svg')).toBeVisible();
expect(await page.evaluate(() => (window as any).__TRUSTED_TYPES_VIOLATIONS__)).toEqual([]);
});

sentryTest(
'renders the screenshot editor without Trusted Types violations',
async ({ getLocalTestUrl, page, browserName }) => {
sentryTest.skip(browserName !== 'chromium', 'The canvas screen-capture fixture requires Chromium.');

await page.addInitScript(() => {
// The fixture runs over HTTP, but screenshot capture is stubbed below.
Object.defineProperty(window, 'isSecureContext', { value: true });
Object.defineProperty(navigator, 'mediaDevices', {
value: {
getDisplayMedia: async () => {
const canvas = document.createElement('canvas');
canvas.width = 800;
canvas.height = 600;
const ctx = canvas.getContext('2d')!;
ctx.fillStyle = 'white';
ctx.fillRect(0, 0, canvas.width, canvas.height);
return canvas.captureStream();
},
},
configurable: true,
});
});

await page.goto(await getLocalTestUrl({ testDir: __dirname }));
await page.getByRole('button', { name: 'Report a Bug', exact: true }).click();
await page.getByRole('button', { name: 'Add a screenshot', exact: true }).click();

await expect(page.locator('.editor__image-container')).toHaveCSS('padding', '15px');
expect(await page.evaluate(() => (window as any).__TRUSTED_TYPES_VIOLATIONS__)).toEqual([]);
},
);
7 changes: 4 additions & 3 deletions packages/feedback/src/modal/components/Dialog.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { FeedbackFormData, FeedbackInternalOptions } from '@sentry/core';
import type { VNode } from 'preact';
import { Fragment, h } from 'preact'; // eslint-disable-line @typescript-eslint/no-unused-vars
import { useCallback, useLayoutEffect, useMemo, useRef, useState } from 'preact/hooks';
import { useCallback, useLayoutEffect, useRef, useState } from 'preact/hooks';
import { SUCCESS_MESSAGE_TIMEOUT } from '../../constants';
import type { Props as HeaderProps } from './DialogHeader';
import { DialogHeader } from './DialogHeader';
Expand All @@ -17,7 +17,6 @@ interface Props extends HeaderProps, FormProps {

export function Dialog({ open, onFormSubmitted, ...props }: Props): VNode {
const options = props.options;
const successIconHtml = useMemo(() => ({ __html: SuccessIcon().outerHTML }), []);

const [timeoutId, setTimeoutId] = useState<NodeJS.Timeout | null>(null);
const dialogRef = useRef<HTMLDialogElement>(null);
Expand Down Expand Up @@ -78,7 +77,9 @@ export function Dialog({ open, onFormSubmitted, ...props }: Props): VNode {
<div class="success__position" onClick={handleOnSuccessClick}>
<div class="success__content">
{options.successMessageText}
<span class="success__icon" dangerouslySetInnerHTML={successIconHtml} />
<span class="success__icon">
<SuccessIcon />
</span>
</div>
</div>
) : (
Expand Down
8 changes: 3 additions & 5 deletions packages/feedback/src/modal/components/DialogHeader.tsx

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

general remark: I'm wondering why we previously didn't render the logos/icons as a Preact component but rather via dangerouslySetInnerHTML. Any ideas?

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.

from what I can tell the icons were just left as-is with minimal changes from their pre-Preact version. Using the plain SVGElement then required dangerouslySetInnerHTML in Preact. See https://github.com/getsentry/sentry-javascript/pull/10590/changes#diff-0b90146add02dcb414427bdcf514cde78470a7e12d95e50b2fec8ad32513a0a2

Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import type { FeedbackInternalOptions } from '@sentry/core';
import type { VNode } from 'preact';
import { h } from 'preact'; // eslint-disable-line @typescript-eslint/no-unused-vars
import { useMemo } from 'preact/hooks';
import { SentryLogo } from './SentryLogo';

export interface Props {
options: FeedbackInternalOptions;
}

export function DialogHeader({ options }: Props): VNode {
const logoHtml = useMemo(() => ({ __html: SentryLogo().outerHTML }), []);

return (
<h2 class="dialog__header">
<span class="dialog__title">{options.formTitle}</span>
Expand All @@ -21,8 +18,9 @@ export function DialogHeader({ options }: Props): VNode {
href="https://sentry.io/welcome/"
title="Powered by Sentry"
rel="noopener noreferrer"
dangerouslySetInnerHTML={logoHtml}
/>
>
<SentryLogo />
</a>
) : null}
</h2>
);
Expand Down
26 changes: 0 additions & 26 deletions packages/feedback/src/modal/components/SentryLogo.ts

This file was deleted.

16 changes: 16 additions & 0 deletions packages/feedback/src/modal/components/SentryLogo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { VNode } from 'preact';
import { h } from 'preact';

/**
* Sentry Logo
*/
export function SentryLogo(): VNode {
return (
<svg width="32" height="30" viewBox="0 0 72 66" fill="inherit">
<path
transform="translate(11, 11)"
d="M29,2.26a4.67,4.67,0,0,0-8,0L14.42,13.53A32.21,32.21,0,0,1,32.17,40.19H27.55A27.68,27.68,0,0,0,12.09,17.47L6,28a15.92,15.92,0,0,1,9.23,12.17H4.62A.76.76,0,0,1,4,39.06l2.94-5a10.74,10.74,0,0,0-3.36-1.9l-2.91,5a4.54,4.54,0,0,0,1.69,6.24A4.66,4.66,0,0,0,4.62,44H19.15a19.4,19.4,0,0,0-8-17.31l2.31-4A23.87,23.87,0,0,1,23.76,44H36.07a35.88,35.88,0,0,0-16.41-31.8l4.67-8a.77.77,0,0,1,1.05-.27c.53.29,20.29,34.77,20.66,35.17a.76.76,0,0,1-.68,1.13H40.6q.09,1.91,0,3.81h4.78A4.59,4.59,0,0,0,50,39.43a4.49,4.49,0,0,0-.62-2.28Z"
/>
</svg>
);
}
54 changes: 0 additions & 54 deletions packages/feedback/src/modal/components/SuccessIcon.ts

This file was deleted.

18 changes: 18 additions & 0 deletions packages/feedback/src/modal/components/SuccessIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { VNode } from 'preact';
import { h } from 'preact';

/**
* Success Icon (checkmark)
*/
export function SuccessIcon(): VNode {
return (
<svg width="16" height="17" viewBox="0 0 16 17" fill="inherit">
<path
fill-rule="evenodd"
clip-rule="evenodd"
d="M3.55544 15.1518C4.87103 16.0308 6.41775 16.5 8 16.5C10.1217 16.5 12.1566 15.6571 13.6569 14.1569C15.1571 12.6566 16 10.6217 16 8.5C16 6.91775 15.5308 5.37103 14.6518 4.05544C13.7727 2.73985 12.5233 1.71447 11.0615 1.10897C9.59966 0.503466 7.99113 0.34504 6.43928 0.653721C4.88743 0.962403 3.46197 1.72433 2.34315 2.84315C1.22433 3.96197 0.462403 5.38743 0.153721 6.93928C-0.15496 8.49113 0.00346625 10.0997 0.608967 11.5615C1.21447 13.0233 2.23985 14.2727 3.55544 15.1518ZM4.40546 3.1204C5.46945 2.40946 6.72036 2.03 8 2.03C9.71595 2.03 11.3616 2.71166 12.575 3.92502C13.7883 5.13838 14.47 6.78405 14.47 8.5C14.47 9.77965 14.0905 11.0306 13.3796 12.0945C12.6687 13.1585 11.6582 13.9878 10.476 14.4775C9.29373 14.9672 7.99283 15.0953 6.73777 14.8457C5.48271 14.596 4.32987 13.9798 3.42502 13.075C2.52018 12.1701 1.90397 11.0173 1.65432 9.76224C1.40468 8.50718 1.5328 7.20628 2.0225 6.02404C2.5122 4.8418 3.34148 3.83133 4.40546 3.1204Z"
/>
<path d="M6.68775 12.4297C6.78586 12.4745 6.89218 12.4984 7 12.5C7.11275 12.4955 7.22315 12.4664 7.32337 12.4145C7.4236 12.3627 7.51121 12.2894 7.58 12.2L12 5.63999C12.0848 5.47724 12.1071 5.28902 12.0625 5.11098C12.0178 4.93294 11.9095 4.77744 11.7579 4.67392C11.6064 4.57041 11.4221 4.52608 11.24 4.54931C11.0579 4.57254 10.8907 4.66173 10.77 4.79999L6.88 10.57L5.13 8.56999C5.06508 8.49566 4.98613 8.43488 4.89768 8.39111C4.80922 8.34735 4.713 8.32148 4.61453 8.31498C4.51605 8.30847 4.41727 8.32147 4.32382 8.35322C4.23038 8.38497 4.14413 8.43484 4.07 8.49999C3.92511 8.63217 3.83692 8.81523 3.82387 9.01092C3.81083 9.2066 3.87393 9.39976 4 9.54999L6.43 12.24C6.50187 12.3204 6.58964 12.385 6.68775 12.4297Z" />
</svg>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export function ScreenshotEditorFactory({
const useTakeScreenshot = useTakeScreenshotFactory({ hooks });
const Toolbar = ToolbarFactory({ h });
const IconClose = IconCloseFactory({ h });
const editorStyleInnerText = { __html: createScreenshotInputStyles(options.styleNonce).innerText };
const editorStyles = createScreenshotInputStyles(options.styleNonce).textContent;

const dialogStyle = (dialog.el as HTMLElement).style;

Expand Down Expand Up @@ -294,7 +294,7 @@ export function ScreenshotEditorFactory({

return (
<div class="editor">
<style nonce={options.styleNonce} dangerouslySetInnerHTML={editorStyleInnerText} />
<style nonce={options.styleNonce}>{editorStyles}</style>
<div class="editor__image-container">
<div class="editor__canvas-container" ref={measurementRef}>
<canvas ref={backgroundRef} id="background" style={dimensions} />
Expand Down
Loading