Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

fix(pages): stop one CDN outage from silently killing signing, charts and QR

nirholas09725b1a75ce
diff --git a/public/ar-forge.html b/public/ar-forge.html
index 4378d9662..cf07da3fe 100644
--- a/public/ar-forge.html
+++ b/public/ar-forge.html
@@ -592,7 +592,11 @@
var qrLibPromise = null;
function loadQrLib() {
if (!qrLibPromise) {
- qrLibPromise = import('https://cdn.jsdelivr.net/npm/[email protected]/+esm')
+ // Through /load-module.js, which races the same package version
+ // across jsdelivr, esm.sh and unpkg. A single-host import meant one
+ // CDN outage silently cost the handoff QR on every desktop visit.
+ qrLibPromise = import('/load-module.js')
+ .then(function (loader) { return loader.loadModule('https://cdn.jsdelivr.net/npm/[email protected]/+esm'); })
.then(function (m) { return m.default || m; });
}
return qrLibPromise;
diff --git a/public/dashboard/agent-pumpfun.html b/public/dashboard/agent-pumpfun.html
index 26999f20f..2e4c55e89 100644
--- a/public/dashboard/agent-pumpfun.html
+++ b/public/dashboard/agent-pumpfun.html
@@ -883,6 +883,17 @@
};
let toastTimer;
+ // Every CDN module on this page goes through /load-module.js, which
+ // races the same package version across esm.sh, jsdelivr and unpkg and
+ // rejects with a typed error naming every host it tried. A bare
+ // import('https://esm.sh/...') made one CDN outage, one corporate
+ // proxy or one ad blocker enough to kill wallet signing and the vanity
+ // grinder with nothing on screen saying why.
+ async function loadCdnModule(url) {
+ const { loadModule } = await import('/load-module.js');
+ return loadModule(url);
+ }
+
function toast(msg, kind = 'ok') {
els.toast.textContent = msg;
els.toast.className = `toast show ${kind}`;
@@ -1209,7 +1220,7 @@
body: JSON.stringify({ domain, wallet_address: pubkey }),
});
- const { VersionedTransaction } = await import('https://esm.sh/@solana/[email protected]');
+ const { VersionedTransaction } = await loadCdnModule('https://esm.sh/@solana/[email protected]');
const tx = VersionedTransaction.deserialize(
Uint8Array.from(atob(prep.tx_base64), (c) => c.charCodeAt(0)),
);
@@ -1684,7 +1695,16 @@
toast('Enter a prefix or suffix', 'err');
return;
}
- const { Keypair } = await import('https://esm.sh/@solana/[email protected]');
+ let Keypair;
+ try {
+ ({ Keypair } = await loadCdnModule('https://esm.sh/@solana/[email protected]'));
+ } catch (err) {
+ // The grinder cannot run without the keypair library. Say so in
+ // the page's own toast rather than leaving the Start button
+ // looking pressed and nothing happening.
+ toast(err?.message || 'The Solana library could not be loaded.', 'err');
+ return;
+ }
vgRunning = true;
vgAbort = false;
vg.start.hidden = true;
diff --git a/public/dashboard/portfolio-asset.html b/public/dashboard/portfolio-asset.html
index ac10f674a..4caa479be 100644
--- a/public/dashboard/portfolio-asset.html
+++ b/public/dashboard/portfolio-asset.html
@@ -529,9 +529,19 @@
renderChart(asset.chart?.points || []);
}
+ // Every CDN module on this page goes through /load-module.js, which
+ // races the same package version across esm.sh, jsdelivr and unpkg and
+ // rejects with a typed error naming every host it tried. A bare
+ // import('https://esm.sh/...') made one CDN outage, one corporate
+ // proxy or one ad blocker enough to blank the feature with no message.
+ async function loadCdnModule(url) {
+ const { loadModule } = await import('/load-module.js');
+ return loadModule(url);
+ }
+
async function ensureChart() {
if (chart) return;
- const mod = await import('https://esm.sh/[email protected]');
+ const mod = await loadCdnModule('https://esm.sh/[email protected]');
const { createChart, AreaSeries } = mod;
chartEl = $$('chart');
chartTooltip = $$('chart-tooltip');
@@ -588,7 +598,18 @@
}
$$('chart').style.display = 'block';
$$('chart-empty').style.display = 'none';
- await ensureChart();
+ try {
+ await ensureChart();
+ } catch (err) {
+ // The price rows on this page are real and already rendered, so
+ // name what is missing instead of leaving an empty chart well.
+ $$('chart').style.display = 'none';
+ const empty = $$('chart-empty');
+ empty.style.display = 'flex';
+ empty.textContent = err?.message || 'The chart library could not be loaded.';
+ $$('chart-change').textContent = '';
+ return;
+ }
const sorted = [...points]
.map((p) => ({ time: Math.floor(new Date(p.t).getTime() / 1000), value: Number(p.price) }))
// lightweight-charts rejects NaN/null values — drop bad rows from upstream
@@ -638,9 +659,19 @@
`, async () => {
$$('close').onclick = closeModal;
$$('qr-copy').onclick = () => navigator.clipboard.writeText(w.address);
- const mod = await import('https://esm.sh/[email protected]');
- const QR = mod.default ?? mod;
- await QR.toCanvas($$('qr-canvas'), w.address, { width: 220, margin: 1, color: { dark: '#000', light: '#ffffff' } });
+ try {
+ const mod = await loadCdnModule('https://esm.sh/[email protected]');
+ const QR = mod.default ?? mod;
+ await QR.toCanvas($$('qr-canvas'), w.address, { width: 220, margin: 1, color: { dark: '#000', light: '#ffffff' } });
+ } catch (err) {
+ // No QR code, but the address below it is the actual payload
+ // and stays readable and copyable, so the modal still works.
+ const note = document.createElement('p');
+ note.className = 'sub';
+ note.style.cssText = 'max-width:220px;text-align:center;margin:0';
+ note.textContent = `${err?.message || 'The QR code library could not be loaded.'} Copy the address below instead.`;
+ $$('qr-canvas').replaceWith(note);
+ }
});
}
diff --git a/public/dashboard/portfolio.html b/public/dashboard/portfolio.html
index bd97fd836..c1921495f 100644
--- a/public/dashboard/portfolio.html
+++ b/public/dashboard/portfolio.html
@@ -1096,11 +1096,23 @@
</div>`;
}
+ // ── Third-party modules ───────────────────────────────────────────
+
+ // Every CDN module on this page goes through /load-module.js, which
+ // races the same package version across esm.sh, jsdelivr and unpkg and
+ // rejects with a typed error naming every host it tried. A bare
+ // import('https://esm.sh/...') made one CDN outage, one corporate
+ // proxy or one ad blocker enough to blank the feature with no message.
+ async function loadCdnModule(url) {
+ const { loadModule } = await import('/load-module.js');
+ return loadModule(url);
+ }
+
// ── Chart ─────────────────────────────────────────────────────────
async function ensureChart() {
if (chart) return;
- const mod = await import('https://esm.sh/[email protected]');
+ const mod = await loadCdnModule('https://esm.sh/[email protected]');
const { createChart, AreaSeries } = mod;
chartEl = $('chart');
chartTooltip = $('chart-tooltip');
@@ -1161,7 +1173,18 @@
}
$('chart').style.display = 'block';
$('chart-empty').style.display = 'none';
- await ensureChart();
+ try {
+ await ensureChart();
+ } catch (err) {
+ // The charting library is unreachable. The balances above are
+ // real and already rendered, so say what is missing and why
+ // rather than leaving an empty 260px hole.
+ $('chart').style.display = 'none';
+ const empty = $('chart-empty');
+ empty.style.display = 'flex';
+ empty.textContent = err?.message || 'The chart library could not be loaded.';
+ return;
+ }
const data = filtered
.map((p) => ({ time: Math.floor(new Date(p.t).getTime() / 1000), value: Number(p.usd) }))
.filter((d) => Number.isFinite(d.time) && Number.isFinite(d.value))
@@ -1207,9 +1230,21 @@
`, async () => {
$('modal-close').onclick = closeModal;
$('qr-copy').onclick = () => navigator.clipboard.writeText(w.address);
- const mod = await import('https://esm.sh/[email protected]');
- const QR = mod.default ?? mod;
- await QR.toCanvas($('qr-canvas'), w.address, { width: 220, margin: 1, color: { dark: '#000', light: '#ffffff' } });
+ try {
+ const mod = await loadCdnModule('https://esm.sh/[email protected]');
+ const QR = mod.default ?? mod;
+ await QR.toCanvas($('qr-canvas'), w.address, { width: 220, margin: 1, color: { dark: '#000', light: '#ffffff' } });
+ } catch (err) {
+ // No QR code, but the address above it is the actual payload
+ // and is still readable and copyable, so the modal stays
+ // usable and explains what is missing.
+ const canvas = $('qr-canvas');
+ const note = document.createElement('p');
+ note.className = 'sub';
+ note.style.cssText = 'max-width:220px;text-align:center;margin:0';
+ note.textContent = `${err?.message || 'The QR code library could not be loaded.'} Copy the address below instead.`;
+ canvas.replaceWith(note);
+ }
});
}
diff --git a/public/dashboard/sns.html b/public/dashboard/sns.html
index f240269a5..eefc0f20a 100644
--- a/public/dashboard/sns.html
+++ b/public/dashboard/sns.html
@@ -155,8 +155,15 @@
}
const { tx_base64 } = prepJson.data;
- const { VersionedTransaction } = await import(
- 'https://esm.sh/@solana/[email protected]'
+ // Through /load-module.js, which races the same package version
+ // across esm.sh, jsdelivr and unpkg and rejects with a typed error
+ // naming every host it tried. A bare import('https://esm.sh/...')
+ // meant one CDN outage or one ad blocker stalled the registration
+ // silently; the error now lands in the caller's catch and is
+ // printed by setRegisterStatus.
+ const { loadModule } = await import('/load-module.js');
+ const { VersionedTransaction } = await loadModule(
+ 'https://esm.sh/@solana/[email protected]',
);
const txBytes = Uint8Array.from(atob(tx_base64), (c) => c.charCodeAt(0));
const tx = VersionedTransaction.deserialize(txBytes);
diff --git a/public/pay/index.html b/public/pay/index.html
index ff4a322c1..d21d885d2 100644
--- a/public/pay/index.html
+++ b/public/pay/index.html
@@ -1129,7 +1129,7 @@ async function runPhantomPayment(call, displayLabel) {
// 3. Phantom signs
setStep('built', 'active', 'sign the transaction in Phantom…');
- const { VersionedTransaction } = await import('https://esm.sh/@solana/web3.js@1');
+ const { VersionedTransaction } = await loadCdnModule('https://esm.sh/@solana/web3.js@1');
const vtxBytes = base64ToUint8Array(tx_base64);
const vtx = VersionedTransaction.deserialize(vtxBytes);
const signedVtx = await provider.signTransaction(vtx);
@@ -1470,6 +1470,17 @@ function resetSteps() {
stepsEl.appendChild(el);
}
}
+// Third-party modules go through /load-module.js, which races the same package
+// version across esm.sh, jsdelivr and unpkg and rejects with a typed error
+// naming every host it tried. A bare import('https://esm.sh/...') meant one CDN
+// outage, one corporate proxy or one ad blocker stalled the payment at "sign
+// the transaction" with nothing on screen saying why. The error lands in the
+// caller's catch, which paints the failed step and the chat error line.
+async function loadCdnModule(url) {
+ const { loadModule } = await import('/load-module.js');
+ return loadModule(url);
+}
+
function setStep(id, state, meta) {
const el = $(`step-${id}`);
if (!el) return;
diff --git a/tests/public-page-cdn-imports.test.js b/tests/public-page-cdn-imports.test.js
new file mode 100644
index 000000000..c68555d6e
--- /dev/null
+++ b/tests/public-page-cdn-imports.test.js
@@ -0,0 +1,107 @@
+// The pages under public/ are served verbatim: no bundler rewrites them, so a
+// bare `import('https://esm.sh/...')` in one is a single point of failure the
+// user meets at the worst possible moment. On /pay it stalled a payment at
+// "sign the transaction in Phantom" with nothing on screen; on the portfolio
+// dashboards it left an empty chart well and a blank QR canvas. One CDN
+// outage, one corporate proxy or one ad blocker was enough.
+//
+// /load-module.js already races the same package version across esm.sh,
+// jsdelivr and unpkg and rejects with a typed error naming every host. This
+// pins that every public page uses it, because the next page added here will
+// otherwise copy the pattern that failed.
+import { describe, it, expect } from 'vitest';
+import { readFileSync, readdirSync, statSync } from 'node:fs';
+import { fileURLToPath } from 'node:url';
+import { dirname, join, relative } from 'node:path';
+
+const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
+const PUBLIC_DIR = join(ROOT, 'public');
+
+function walk(dir, out = []) {
+ for (const entry of readdirSync(dir)) {
+ // public/chat is a build output copied in by `npm run build:chat`; it is
+ // not hand-written source and is not ours to hold to this rule.
+ if (entry === 'chat' || entry === 'node_modules') continue;
+ const full = join(dir, entry);
+ if (statSync(full).isDirectory()) walk(full, out);
+ else if (/\.html$/.test(entry)) out.push(full);
+ }
+ return out;
+}
+
+// The three hosts /load-module.js knows how to mirror between.
+const MIRRORABLE = /^https:\/\/(?:esm\.sh|cdn\.jsdelivr\.net|unpkg\.com)\//;
+
+// Comments quote the very pattern they warn against, so strip them before
+// scanning; otherwise the explanation of the fix reads as the defect.
+function withoutComments(src) {
+ return src.replace(/\/\*[\s\S]*?\*\//g, ' ').replace(/(^|[^:'"`])\/\/[^\n]*/g, '$1');
+}
+
+/** Every mirrorable CDN URL a page hands to the loader (directly or via a wrapper). */
+function loaderCdnTargets(src) {
+ const out = [];
+ const re = /\b(?:loadModule|loadCdnModule)\s*\(\s*['"`]([^'"`]+)['"`]/g;
+ for (const m of withoutComments(src).matchAll(re)) {
+ if (MIRRORABLE.test(m[1])) out.push(m[1]);
+ }
+ return out;
+}
+
+/** Every string literal a page passes straight to `import()` from a CDN host. */
+function cdnImportTargets(src) {
+ const out = [];
+ const re = /\bimport\s*\(\s*['"`]([^'"`]+)['"`]/g;
+ for (const m of withoutComments(src).matchAll(re)) {
+ if (MIRRORABLE.test(m[1])) out.push(m[1]);
+ }
+ return out;
+}
+
+describe('public pages load third-party modules through /load-module.js', () => {
+ const pages = walk(PUBLIC_DIR);
+
+ it('finds the public pages to check', () => {
+ expect(pages.length).toBeGreaterThan(10);
+ });
+
+ it('has no bare CDN dynamic import left in any page', () => {
+ const offenders = [];
+ for (const file of pages) {
+ const targets = cdnImportTargets(readFileSync(file, 'utf8'));
+ if (targets.length) offenders.push(`${relative(ROOT, file)}: ${targets.join(', ')}`);
+ }
+ expect(offenders).toEqual([]);
+ });
+
+ it('keeps the loader wired into every page the audit fixed', () => {
+ // The sweep above also passes if a feature is simply deleted. These are
+ // the pages that used to import a CDN host directly; each must still
+ // reach it, through the loader, by ABSOLUTE path (they live at several
+ // depths, and a relative path breaks the moment a page moves).
+ const fixed = [
+ 'public/pay/index.html',
+ 'public/dashboard/portfolio.html',
+ 'public/dashboard/portfolio-asset.html',
+ 'public/dashboard/agent-pumpfun.html',
+ 'public/dashboard/sns.html',
+ 'public/agent-passport.html',
+ 'public/ar-forge.html',
+ ];
+ for (const rel of fixed) {
+ const src = withoutComments(readFileSync(join(ROOT, rel), 'utf8'));
+ expect(/['"]\/load-module\.js['"]/.test(src), `${rel} must import '/load-module.js'`).toBe(true);
+ expect(/\b(?:loadModule|loadCdnModule)\s*\(/.test(src), `${rel} must call the loader`).toBe(true);
+ expect(MIRRORABLE.test(''), 'MIRRORABLE guards a full URL, not a bare host').toBe(false);
+ }
+ });
+
+ it('the loader those pages import is actually served at that path', () => {
+ // public/ is Vite's publicDir, copied to the site root, so /load-module.js
+ // is public/load-module.js. If this file ever moves, every page above 404s
+ // at exactly the moment it needs a fallback.
+ expect(() => statSync(join(PUBLIC_DIR, 'load-module.js'))).not.toThrow();
+ const loader = readFileSync(join(PUBLIC_DIR, 'load-module.js'), 'utf8');
+ expect(loader).toContain('export function loadModule');
+ });
+});