fix script tag in repl mode

This commit is contained in:
Yanzhen Yu
2026-04-01 12:00:00 +08:00
parent 01bd1d26c1
commit df990cd731
2 changed files with 9 additions and 14 deletions

View File

@@ -1,7 +1,4 @@
{ {
"non-interactive": true, "non-interactive": true,
"buildCommand": "npm run bundle", "buildCommand": "npm run bundle"
"src": {
"tag": "false"
}
} }

View File

@@ -14,13 +14,6 @@ function getCode(): string {
return fs.readFileSync(bundlePath, 'utf8'); return fs.readFileSync(bundlePath, 'utf8');
} }
function safeStringify(obj: Object): string {
return JSON.stringify(obj)
.replace(/&/g, '&amp')
.replace(/</g, '&lt')
.replace(/>/g, '&gt');
}
(async () => { (async () => {
const code = getCode(); const code = getCode();
@@ -117,7 +110,7 @@ function safeStringify(obj: Object): string {
path: path.resolve(__dirname, '../dist/rrweb.min.css'), path: path.resolve(__dirname, '../dist/rrweb.min.css'),
}); });
await page.evaluate(`${code} await page.evaluate(`${code}
const events = ${safeStringify(events)}; const events = ${JSON.stringify(events)};
const replayer = new rrweb.Replayer(events); const replayer = new rrweb.Replayer(events);
replayer.play(); replayer.play();
`); `);
@@ -146,8 +139,13 @@ function safeStringify(obj: Object): string {
<body> <body>
<script src="../dist/rrweb.min.js"></script> <script src="../dist/rrweb.min.js"></script>
<script> <script>
const data = ${safeStringify({ events })} /*<!--*/
const replayer = new rrweb.Replayer(data.events); const events = ${JSON.stringify(events).replace(
/<\/script>/g,
'<\\/script>',
)};
/*-->*/
const replayer = new rrweb.Replayer(events);
replayer.play(); replayer.play();
</script> </script>
</body> </body>