Skip to content

Commit

Permalink
Don't use XMLSerializer for snapshots
Browse files Browse the repository at this point in the history
XMLSerializer outputs a conformant XML document, which we actually don't want;
'>' characters inside CSS <style>s end up escaped, and the HTML5 parser doesn't
unescape them when parsing, so it breaks some page styles. Use outerHTML and
manually add the <!DOCTYPE> instead.

Fixes zotero/zotero#3424
  • Loading branch information
AbeJellinek committed Sep 15, 2023
1 parent df7862f commit adb57a4
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/dom/snapshot/snapshot-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ class SnapshotView extends DOMView<SnapshotViewState, SnapshotViewData> {
noscript.remove();
}

return new XMLSerializer().serializeToString(doc);
let doctype = doc.doctype ? new XMLSerializer().serializeToString(doc.doctype) : '';
let html = doc.documentElement.outerHTML;
return doctype + html;
}
else {
throw new Error('buf, url, or srcDoc is required');
Expand Down

0 comments on commit adb57a4

Please sign in to comment.