fix: resolve element .src to an absolute URL (#255) (#260)

HTMLScriptElement/HTMLImageElement .src reflected the literal attribute
instead of the resolved absolute URL. Loaders that derive their base with
new URL(document.currentScript.src).origin threw "Invalid URL" on a
relative src and aborted, so the page bundle never loaded and the DOM
stayed empty (issue #255). getAttribute("src") still returns the literal.
This commit is contained in:
SGavrl authored and GitHub committed 2026-06-07 11:42:56 +02:00
1 parent 5135e3cb4d
commit c1e0b0fb5a
1 file changed
+10 -1
+10 -1
View File
@@ -1440,7 +1440,16 @@ class Element extends Node {
get hash() { const u = (this.localName === 'a' || this.localName === 'area') ? _elemHrefURL(this) : null; return u ? u.hash : ''; }
set hash(v) { if (this.localName === 'a' || this.localName === 'area') _setElemHrefPart(this, 'hash', v); }
get origin() { const u = (this.localName === 'a' || this.localName === 'area') ? _elemHrefURL(this) : null; return u ? u.origin : ''; }
get src() { return this.getAttribute("src") || ""; }
get src() {
// IDL reflection: HTMLScriptElement/HTMLImageElement/etc. `.src` returns the
// resolved absolute URL, not the literal attribute. Loaders that compute their
// base via `new URL(document.currentScript.src).origin` break on a relative
// value (issue #255). getAttribute("src") still returns the literal.
const v = this.getAttribute("src");
if (!v) return "";
try { return new URL(v, globalThis.location?.href || "about:blank").href; }
catch (e) { return v; }
}
set src(v) {
this.setAttribute("src", v);
if (this.localName === 'iframe' && v && v !== 'about:blank') {