Skip to content

Commit 95ea260

Browse files
committed
see pr: niklasvh#2846
1 parent f42ae6d commit 95ea260

File tree

1 file changed

+5
-28
lines changed

1 file changed

+5
-28
lines changed

src/dom/document-cloner.ts

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,13 @@ export class DocumentCloner {
130130
});
131131

132132
documentClone.open();
133-
documentClone.write(`${serializeDoctype(document.doctype)}<html></html>`);
133+
if (document.doctype && document.doctype.nodeType === Node.DOCUMENT_TYPE_NODE) {
134+
const doctypeClone = document.doctype.cloneNode(false);
135+
documentClone.append(doctypeClone);
136+
}
134137
// Chrome scrolls the parent document for some reason after the write to the cloned window???
135138
restoreOwnerScroll(this.referenceElement.ownerDocument, scrollX, scrollY);
136-
documentClone.replaceChild(documentClone.adoptNode(this.documentElement), documentClone.documentElement);
139+
documentClone.append(documentClone.adoptNode(this.documentElement));
137140
documentClone.close();
138141

139142
return iframeLoad;
@@ -568,32 +571,6 @@ export const copyCSSStyles = <T extends HTMLElement | SVGElement>(style: CSSStyl
568571
return target;
569572
};
570573

571-
const serializeDoctype = (doctype?: DocumentType | null): string => {
572-
let str = '';
573-
if (doctype) {
574-
str += '<!DOCTYPE ';
575-
if (doctype.name) {
576-
str += doctype.name;
577-
}
578-
579-
if (doctype.internalSubset) {
580-
str += doctype.internalSubset;
581-
}
582-
583-
if (doctype.publicId) {
584-
str += `"${doctype.publicId}"`;
585-
}
586-
587-
if (doctype.systemId) {
588-
str += `"${doctype.systemId}"`;
589-
}
590-
591-
str += '>';
592-
}
593-
594-
return str;
595-
};
596-
597574
const restoreOwnerScroll = (ownerDocument: Document | null, x: number, y: number) => {
598575
if (
599576
ownerDocument &&

0 commit comments

Comments
 (0)