Skip to content

Commit

Permalink
Updated to include fix for trusted types comply
Browse files Browse the repository at this point in the history
  • Loading branch information
ihems committed Apr 17, 2023
1 parent 6020386 commit c1a31a8
Showing 1 changed file with 5 additions and 28 deletions.
33 changes: 5 additions & 28 deletions src/dom/document-cloner.ts
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 c1a31a8

Please sign in to comment.