Skip to content

Commit

Permalink
see pr: niklasvh#2846
Browse files Browse the repository at this point in the history
  • Loading branch information
nangelina committed Feb 8, 2024
1 parent f42ae6d commit 95ea260
Showing 1 changed file with 5 additions and 28 deletions.
33 changes: 5 additions & 28 deletions src/dom/document-cloner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,13 @@ export class DocumentCloner {
});

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

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

const serializeDoctype = (doctype?: DocumentType | null): string => {
let str = '';
if (doctype) {
str += '<!DOCTYPE ';
if (doctype.name) {
str += doctype.name;
}

if (doctype.internalSubset) {
str += doctype.internalSubset;
}

if (doctype.publicId) {
str += `"${doctype.publicId}"`;
}

if (doctype.systemId) {
str += `"${doctype.systemId}"`;
}

str += '>';
}

return str;
};

const restoreOwnerScroll = (ownerDocument: Document | null, x: number, y: number) => {
if (
ownerDocument &&
Expand Down

0 comments on commit 95ea260

Please sign in to comment.