mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
Updated to include fix for trusted types comply
This commit is contained in:
parent
6020386bbe
commit
c1a31a8fa6
@ -130,10 +130,13 @@ export class DocumentCloner {
|
|||||||
});
|
});
|
||||||
|
|
||||||
documentClone.open();
|
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???
|
// Chrome scrolls the parent document for some reason after the write to the cloned window???
|
||||||
restoreOwnerScroll(this.referenceElement.ownerDocument, scrollX, scrollY);
|
restoreOwnerScroll(this.referenceElement.ownerDocument, scrollX, scrollY);
|
||||||
documentClone.replaceChild(documentClone.adoptNode(this.documentElement), documentClone.documentElement);
|
documentClone.append(documentClone.adoptNode(this.documentElement));
|
||||||
documentClone.close();
|
documentClone.close();
|
||||||
|
|
||||||
return iframeLoad;
|
return iframeLoad;
|
||||||
@ -568,32 +571,6 @@ export const copyCSSStyles = <T extends HTMLElement | SVGElement>(style: CSSStyl
|
|||||||
return target;
|
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) => {
|
const restoreOwnerScroll = (ownerDocument: Document | null, x: number, y: number) => {
|
||||||
if (
|
if (
|
||||||
ownerDocument &&
|
ownerDocument &&
|
||||||
|
Loading…
x
Reference in New Issue
Block a user