|
16 | 16 | <!DOCTYPE html> |
17 | 17 | <html lang="en" translate="no"> |
18 | 18 | <head> |
19 | | - <meta charset="UTF-8"> |
20 | | - <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
21 | | - <link rel="icon" href="/playwright-logo.svg" type="image/svg+xml"> |
22 | | - <link rel="manifest" href="/manifest.webmanifest"> |
| 19 | + <meta charset="UTF-8" /> |
| 20 | + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
| 21 | + <link rel="icon" href="/playwright-logo.svg" type="image/svg+xml" /> |
| 22 | + <link rel="manifest" href="/manifest.webmanifest" /> |
23 | 23 | <title>Playwright Trace Viewer</title> |
24 | 24 | </head> |
25 | 25 | <body> |
26 | 26 | <div id="root"></div> |
27 | 27 | <script type="module" src="/src/index.tsx"></script> |
28 | 28 | <dialog id="fallback-error"> |
29 | | - <p>The Playwright Trace Viewer must be loaded over the <code>http://</code> or <code>https://</code> protocols.</p> |
30 | | - <p>For more information, please see the <a href="https://aka.ms/playwright/trace-viewer-file-protocol">docs</a>.</p> |
| 29 | + <p> |
| 30 | + The Playwright Trace Viewer must be loaded over the |
| 31 | + <code>http://</code> or <code>https://</code> protocols. |
| 32 | + </p> |
| 33 | + <p> |
| 34 | + For more information, please see the |
| 35 | + <a href="https://aka.ms/playwright/trace-viewer-file-protocol">docs</a>. |
| 36 | + </p> |
31 | 37 | </dialog> |
32 | 38 | <script> |
33 | 39 | if (!/^https?:/.test(window.location.protocol)) { |
34 | | - const fallbackErrorDialog = document.getElementById('fallback-error'); |
35 | | - const isTraceViewerInsidePlaywrightReport = window.location.protocol === 'file:' && window.location.pathname.endsWith('/trace/index.html'); |
36 | | - // Best-effort to show the report path in the dialog. |
| 40 | + const fallbackErrorDialog = document.getElementById("fallback-error"); |
| 41 | + |
| 42 | + const isTraceViewerInsidePlaywrightReport = |
| 43 | + window.location.protocol === "file:" && |
| 44 | + decodeURIComponent(window.location.pathname).endsWith( |
| 45 | + "/trace/index.html" |
| 46 | + ); |
| 47 | + |
37 | 48 | if (isTraceViewerInsidePlaywrightReport) { |
| 49 | + const basePathname = decodeURIComponent(window.location.pathname); |
| 50 | + const base = basePathname.replace(/\/trace\/index\.html$/, ""); |
| 51 | + |
38 | 52 | const reportPath = (() => { |
39 | | - const base = window.location.pathname.replace(/\/trace\/index\.html$/, ''); |
40 | | - if (navigator.platform === 'Win32') |
41 | | - return base.replace(/^\//, '').replace(/\//g, '\\\\'); |
| 53 | + if (navigator.platform === "Win32") { |
| 54 | + return base.replace(/^\//, "").replace(/\//g, "\\"); |
| 55 | + } |
42 | 56 | return base; |
43 | 57 | })(); |
44 | | - const reportLink = document.createElement('div'); |
45 | | - const command = `npx playwright show-report ${reportPath}`; |
46 | | - reportLink.innerHTML = `You can open the report via <code>${command}</code> from your Playwright project. <button type="button">Copy Command</button>`; |
47 | | - fallbackErrorDialog.insertBefore(reportLink, fallbackErrorDialog.children[1]); |
48 | | - reportLink.querySelector('button').addEventListener('click', () => navigator.clipboard.writeText(command)); |
| 58 | + |
| 59 | + const command = `npx playwright show-report "${reportPath}"`; |
| 60 | + |
| 61 | + const reportLink = document.createElement("div"); |
| 62 | + reportLink.innerHTML = |
| 63 | + `You can open the report via <code>${command}</code> from your Playwright project. ` + |
| 64 | + `<button type="button">Copy Command</button>`; |
| 65 | + fallbackErrorDialog.insertBefore( |
| 66 | + reportLink, |
| 67 | + fallbackErrorDialog.children[1] |
| 68 | + ); |
| 69 | + |
| 70 | + const copyBtn = reportLink.querySelector("button"); |
| 71 | + if (copyBtn) { |
| 72 | + copyBtn.addEventListener("click", () => |
| 73 | + navigator.clipboard.writeText(command) |
| 74 | + ); |
| 75 | + } |
49 | 76 | } |
| 77 | + |
50 | 78 | fallbackErrorDialog.show(); |
51 | 79 | } |
52 | 80 | </script> |
|
0 commit comments