Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(snapshot): properly save textarea content #3835

Merged
merged 1 commit into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/trace/snapshotterInjected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ export function takeSnapshotInFrame(guid: string, removeNoScript: boolean): Snap
builder.push(escapeAttribute(value));
builder.push('"');
}
if (nodeName === 'INPUT' || nodeName === 'TEXTAREA') {
if (nodeName === 'INPUT') {
builder.push(' value="');
builder.push(escapeAttribute((element as HTMLInputElement | HTMLTextAreaElement).value));
builder.push(escapeAttribute((element as HTMLInputElement).value));
builder.push('"');
}
if ((element as any).checked)
Expand Down Expand Up @@ -237,8 +237,12 @@ export function takeSnapshotInFrame(guid: string, removeNoScript: boolean): Snap
}
builder.push('>');
}
for (let child = node.firstChild; child; child = child.nextSibling)
visit(child, builder);
if (nodeName === 'TEXTAREA') {
builder.push(escapeText((node as HTMLTextAreaElement).value));
} else {
for (let child = node.firstChild; child; child = child.nextSibling)
visit(child, builder);
}
if (node.nodeName === 'BODY' && chunks.size) {
builder.push('<script>');
const shadowChunks = Array.from(chunks).map(([chunkId, html]) => {
Expand Down
3 changes: 3 additions & 0 deletions test/assets/snapshot/snapshot-with-css.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
}
</style>
<div>hello, world!</div>
<textarea>Before edit</textarea>
<div class=root></div>
<script>
let shadow;

window.addEventListener('DOMContentLoaded', () => {
document.querySelector('textarea').value = 'After edit';

const root = document.querySelector('.root');
shadow = root.attachShadow({ mode: 'open' });

Expand Down