mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
fix: add image ready check
This commit is contained in:
parent
2608ff278b
commit
8546f1eaa2
@ -97,6 +97,8 @@ export class DocumentCloner {
|
||||
await documentClone.fonts.ready;
|
||||
}
|
||||
|
||||
await imagesReady(documentClone);
|
||||
|
||||
if (typeof onclone === 'function') {
|
||||
return Promise.resolve()
|
||||
.then(() => onclone(documentClone))
|
||||
@ -462,6 +464,25 @@ const createIFrameContainer = (ownerDocument: Document, bounds: Bounds): HTMLIFr
|
||||
return cloneIframeContainer;
|
||||
};
|
||||
|
||||
const imageReady = (img: HTMLImageElement): Promise<Event | void> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (img.complete) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
if (!img.src) {
|
||||
reject();
|
||||
return;
|
||||
}
|
||||
img.onload = resolve;
|
||||
img.onerror = reject;
|
||||
});
|
||||
};
|
||||
|
||||
const imagesReady = (document: HTMLDocument): Promise<unknown[]> => {
|
||||
return Promise.all([].slice.call(document.images, 0).map(imageReady));
|
||||
};
|
||||
|
||||
const iframeLoader = (iframe: HTMLIFrameElement): Promise<HTMLIFrameElement> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const cloneWindow = iframe.contentWindow;
|
||||
|
Loading…
x
Reference in New Issue
Block a user