Skip to content

Commit d963d12

Browse files
authored
fix(trace-viewer): decode + quote report path in fallback “Copy Command” (file://) (#37710)
1 parent 26d0024 commit d963d12

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

packages/trace-viewer/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@
3636
// Best-effort to show the report path in the dialog.
3737
if (isTraceViewerInsidePlaywrightReport) {
3838
const reportPath = (() => {
39-
const base = window.location.pathname.replace(/\/trace\/index\.html$/, '');
39+
const base = decodeURIComponent(window.location.pathname).replace(/\/trace\/index\.html$/, '');
4040
if (navigator.platform === 'Win32')
4141
return base.replace(/^\//, '').replace(/\//g, '\\\\');
4242
return base;
4343
})();
4444
const reportLink = document.createElement('div');
45-
const command = `npx playwright show-report ${reportPath}`;
45+
const command = `npx playwright show-report "${reportPath}"`;
4646
reportLink.innerHTML = `You can open the report via <code>${command}</code> from your Playwright project. <button type="button">Copy Command</button>`;
4747
fallbackErrorDialog.insertBefore(reportLink, fallbackErrorDialog.children[1]);
4848
reportLink.querySelector('button').addEventListener('click', () => navigator.clipboard.writeText(command));

tests/playwright-test/reporter-html.spec.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2943,6 +2943,7 @@ for (const useIntermediateMergeReport of [true, false] as const) {
29432943
await expect(page.locator('.test-case-path')).toHaveText('Root describe');
29442944
});
29452945

2946+
29462947
test('should print a user-friendly warning when opening a trace via file:// protocol', async ({ runInlineTest, showReport, page }) => {
29472948
await runInlineTest({
29482949
'playwright.config.ts': `
@@ -2965,10 +2966,16 @@ for (const useIntermediateMergeReport of [true, false] as const) {
29652966
const reportPath = path.join(test.info().outputPath(), 'playwright-report');
29662967
await page.goto(url.pathToFileURL(path.join(reportPath, 'index.html')).toString());
29672968
await page.getByRole('link', { name: 'View trace' }).click();
2968-
await expect(page.locator('#fallback-error')).toContainText('The Playwright Trace Viewer must be loaded over the http:// or https:// protocols.');
2969-
await expect(page.locator('#fallback-error')).toContainText(`npx playwright show-report ${reportPath.replace(/\\/g, '\\\\')}`);
2969+
await expect(page.locator('#fallback-error')).toContainText(
2970+
'The Playwright Trace Viewer must be loaded over the http:// or https:// protocols.'
2971+
);
2972+
const expectedReportPath = reportPath.replace(/\\/g, '\\\\');
2973+
await expect(page.locator('#fallback-error')).toContainText(
2974+
`npx playwright show-report "${expectedReportPath}"`
2975+
);
29702976
});
29712977

2978+
29722979
test('should not collate identical file names in different project directories', async ({ runInlineTest, page }) => {
29732980
await runInlineTest({
29742981
'playwright.config.ts': `

0 commit comments

Comments
 (0)