Updated to include fix for trusted types comply

This commit is contained in:
Ivy HE 2023-04-17 12:19:47 -07:00
parent 6020386bbe
commit c1a31a8fa6
1 changed files with 5 additions and 28 deletions

View File

@ -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;
@ -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 &&