From 0804f8efa6e4efb92af3d17f1a0c4ef2bf0141c8 Mon Sep 17 00:00:00 2001 From: Julian Dice <19397727+windoze95@users.noreply.github.com> Date: Tue, 7 Jul 2026 18:33:47 -0500 Subject: [PATCH] fix(mcp): poll for late ChatGPT window.openai delivery + temp host diagnostic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The window.openai render path didn't resolve the ChatGPT stuck-loading widget. Add a short poll for window.openai.toolOutput (catches a delivery that lands after mount without an openai:set_globals event), and — if nothing renders after ~6s — replace the loading note with a diagnostic of what the host actually exposes (window.openai presence + keys), so we can see inside the cross-origin sandbox iframe. Diagnostic is temporary. Co-Authored-By: Claude Opus 4.8 (1M context) --- internal/mcpserver/widget/app.html | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/internal/mcpserver/widget/app.html b/internal/mcpserver/widget/app.html index 6081f53..d635e07 100644 --- a/internal/mcpserver/widget/app.html +++ b/internal/mcpserver/widget/app.html @@ -700,6 +700,31 @@ }).catch(() => { /* not an MCP Apps postMessage host */ }); resizeObserver.observe(document.body); })(); + +// ChatGPT can set window.openai.toolOutput a tick after mount without firing +// "openai:set_globals" — poll briefly so we don't miss a late delivery. If nothing +// has rendered after a few seconds, surface what the host actually exposes instead +// of sitting on the loading note. (Diagnostic string removed once ChatGPT render +// is confirmed.) +(function watchOpenAI() { + let n = 0; + const timer = setInterval(() => { + n++; + const oa = openAIHost(); + if (oa && oa.toolOutput) { clearInterval(timer); applyOpenAIGlobals(oa); return; } + if (n >= 24) { + clearInterval(timer); + if (root.textContent.indexOf("Warming up") !== -1) { + const o = openAIHost(); + const info = o + ? "openai present; keys: " + Object.keys(o).slice(0, 14).join(", ") + "; toolOutput " + (o.toolOutput ? "set" : "absent") + : "window.openai ABSENT in this iframe"; + clearRoot(); + root.appendChild(el("div", "note", "SaltyBytes debug — " + info)); + } + } + }, 250); +})();