From c1e0b0fb5a3de2052c7068324e311f696023fea7 Mon Sep 17 00:00:00 2001 From: SGavrl <277843151+SGavrl@users.noreply.github.com> Date: Sun, 7 Jun 2026 09:42:56 +0000 Subject: [PATCH] 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. --- crates/obscura-js/js/bootstrap.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/obscura-js/js/bootstrap.js b/crates/obscura-js/js/bootstrap.js index 56eeb12..5f19af8 100644 --- a/crates/obscura-js/js/bootstrap.js +++ b/crates/obscura-js/js/bootstrap.js @@ -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') {