Problem
Playwright's HTML report breaks when assets are inlined into index.html.
The generated inline report.js bundle contains a literal </script> sequence.
Because the reporter injects the bundle directly into a <script type=\"module\"> block, the browser terminates the script early and renders the rest of the bundle as page text.
Expected
npx playwright show-report should render the HTML report UI normally.
Actual
The page at http://localhost:9323 displays raw JavaScript from the report bundle instead of the report UI.
Root Cause
In node_modules/playwright/lib/reporters/html.js, the HTML reporter inlines report.js with:
html = html.replace(/<script type=\"module\"[^>]*><\\/script>/, () => `<script type=\"module\">${js}</script>`);
The bundled report.js contains a literal </script> sequence from React DOM internals:
s.innerHTML="<script></script>"
That makes the inline HTML unsafe because the browser parser closes the script tag before the bundle finishes.
Repro
- Run
npx playwright test.
- Run
npx playwright show-report.
- Open
http://localhost:9323.
- The page shows raw JS text instead of the report UI.
Workaround
Set PLAYWRIGHT_HTML_DO_NOT_INLINE_ASSETS=1 so the reporter keeps report.js external instead of embedding it into index.html.
Notes
The generated report data archive is valid.
The failure is specific to inline HTML script injection, not to the report JSON or attachments.
Recommended Fix
Escape the embedded JS before writing it into the HTML script tag, or stop inlining the JS bundle entirely when generating the report.
Problem
Playwright's HTML report breaks when assets are inlined into
index.html.The generated inline
report.jsbundle contains a literal</script>sequence.Because the reporter injects the bundle directly into a
<script type=\"module\">block, the browser terminates the script early and renders the rest of the bundle as page text.Expected
npx playwright show-reportshould render the HTML report UI normally.Actual
The page at
http://localhost:9323displays raw JavaScript from the report bundle instead of the report UI.Root Cause
In
node_modules/playwright/lib/reporters/html.js, the HTML reporter inlinesreport.jswith:The bundled
report.jscontains a literal</script>sequence from React DOM internals:That makes the inline HTML unsafe because the browser parser closes the script tag before the bundle finishes.
Repro
npx playwright test.npx playwright show-report.http://localhost:9323.Workaround
Set
PLAYWRIGHT_HTML_DO_NOT_INLINE_ASSETS=1so the reporter keepsreport.jsexternal instead of embedding it intoindex.html.Notes
The generated report data archive is valid.
The failure is specific to inline HTML script injection, not to the report JSON or attachments.
Recommended Fix
Escape the embedded JS before writing it into the HTML script tag, or stop inlining the JS bundle entirely when generating the report.