app
Widget Registry
Public Made by Adomby adom
The reviewed registry of widgets renderable from plain markdown on any wiki page
← Commit history
adom-stock: wait for the parser before reading inline data; uncredentialed fetch (the cap carries identity)
1 file changed
+4−1
widgets/stock-widget.js+4−1@@ -19,6 +19,9 @@ a.pill:hover{border-color:var(--accent)}.pill .v{color:var(--muted);font-size:11 const root = this.shadowRoot; root.innerHTML = `<style>${CSS}</style><div class="wrap"><span class="note">checking the distributors</span><span class="when"></span></div>`; let data = null, err = null;+ // The element is defined before the body parses, so this hook can fire before the inline+ // data child exists: wait for the parser to finish before deciding whether to fetch.+ if (!this.querySelector('script[type="application/json"]') && document.readyState === 'loading') await new Promise(r => document.addEventListener('DOMContentLoaded', r, { once: true })); const inline = this.querySelector('script[type="application/json"]'); if (inline) { try { data = JSON.parse(inline.textContent); } catch (e) { err = 'bad inline data'; } } const src = this.getAttribute('src');@@ -36,7 +39,7 @@ a.pill:hover{border-color:var(--accent)}.pill .v{color:var(--muted);font-size:11 // The frame is opaque-origin (no session); the src carries the user cap the wiki minted for a signed-in reader. let cap = ''; try { cap = new URL(src, 'https://wiki.adom.inc').searchParams.get('cap') || ''; } catch (e) {} const headers = fresh ? { 'X-Adom-Widget': 'stock', ...(cap ? { 'X-Adom-Cap': cap } : {}) } : {};- try { const r = await fetch(src, { credentials: 'include', headers }); const data = await r.json(); return { data, err: r.ok ? null : (data && data.error ? data.error : `stock route answered ${r.status}`) }; }+ try { const r = await fetch(src, { credentials: 'omit', headers }); const data = await r.json(); return { data, err: r.ok ? null : (data && data.error ? data.error : `stock route answered ${r.status}`) }; } catch (e) { return { data: null, err: 'could not reach the stock route (' + (e && e.message ? String(e.message).slice(0, 60) : 'blocked') + ')' }; } } render(d, err) {