diff --git a/packages/browser/src/node/serverOrchestrator.ts b/packages/browser/src/node/serverOrchestrator.ts
index e730fad0c555..ff84adf4c9be 100644
--- a/packages/browser/src/node/serverOrchestrator.ts
+++ b/packages/browser/src/node/serverOrchestrator.ts
@@ -61,7 +61,7 @@ export async function resolveOrchestrator(
for (const attr in script.attrs || {}) {
html += `${attr}="${script.attrs![attr]}" `
}
- html += `>${script.children}`
+ html += `>${escapeInlineScript(typeof script.children === 'string' ? script.children : '')}`
return html
}).join('\n')
}
@@ -96,8 +96,14 @@ export async function resolveOrchestrator(
__VITEST_FAVICON__: globalServer.faviconUrl,
__VITEST_TITLE__: 'Vitest Browser Runner',
__VITEST_SCRIPTS__: globalServer.orchestratorScripts,
- __VITEST_INJECTOR__: ``,
+ __VITEST_INJECTOR__: ``,
__VITEST_ERROR_CATCHER__: ``,
__VITEST_SESSION_ID__: JSON.stringify(sessionId),
})
}
+
+function escapeInlineScript(content: string): string {
+ return content
+ .replace(/