diff --git a/src/embed-images.ts b/src/embed-images.ts index e8a075c2..6da82d42 100644 --- a/src/embed-images.ts +++ b/src/embed-images.ts @@ -40,8 +40,14 @@ async function embedImageNode( const dataURL = await resourceToDataURL(url, getMimeType(url), options) await new Promise((resolve, reject) => { - clonedNode.decode = resolve + clonedNode.onload = resolve clonedNode.onerror = reject + + const image = clonedNode as HTMLImageElement + if (image.decode) { + image.decode = resolve as any + } + if (clonedNode instanceof HTMLImageElement) { clonedNode.srcset = '' clonedNode.src = dataURL diff --git a/src/util.ts b/src/util.ts index abff7bf5..2e375735 100644 --- a/src/util.ts +++ b/src/util.ts @@ -183,10 +183,11 @@ export function canvasToBlob( export function createImage(url: string): Promise { return new Promise((resolve, reject) => { const img = new Image() - img.decode = () => resolve(img) + img.decode = () => resolve(img) as any + img.onload = () => resolve(img) img.onerror = reject img.crossOrigin = 'anonymous' - img.decoding = 'sync' + img.decoding = 'async' img.src = url }) }