// embed.js - This script is injected into the host page to create and manage the chatbot iframe (function () { const isDev = window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1"; const baseUrl = isDev ? "http://localhost:3000" : "https://ragbot-two.vercel.app"; const iframe = document.createElement("iframe"); iframe.id = "ragbot-iframe"; iframe.src = `${baseUrl}/embed?parentUrl=${encodeURIComponent(window.location.href)}`; iframe.style.cssText = "position:fixed;bottom:24px;right:24px;width:400px;height:520px;border:none;z-index:9999;background:transparent;color-scheme:normal;"; iframe.setAttribute("allowtransparency", "true"); document.body.appendChild(iframe); let lastUrl = window.location.href; const observer = new MutationObserver(() => { if (lastUrl !== window.location.href) { lastUrl = window.location.href; iframe.src = `${baseUrl}/embed?parentUrl=${encodeURIComponent(lastUrl)}`; } }); observer.observe(document.body, { childList: true, subtree: true }); window.addEventListener("popstate", () => { iframe.src = `${baseUrl}/embed?parentUrl=${encodeURIComponent(window.location.href)}`; }); })();