Images created using `document.currentScript.ownerDocument.createElement` (from within <link> imported HTML) never load
问题 Here's a function that returns the width of an image, given the image's url: async function getImageWidthByUrl(imgUrl) { const imgEl = document.createElement("img"); let untilImgLoaded = new Promise((resolve, reject) => { imgEl.onload = resolve; imgEl.onerror = reject; }); imgEl.src = imgUrl; await untilImgLoaded; return imgEl.naturalWidth; } It works fine. It also (of course) works if we use new Image() instead of document.createElement("img") . However, the document.createElement("img")