Widget Troubleshooting
"window is not defined" (SSR/Next.js)
The SDK accesses window and document on import. In SSR environments:
Next.js App Router — use "use client" directive:
"use client";
import { useMasheev } from "@masheev/embed-sdk/react";Next.js dynamic import (if the module has side effects at import time):
import dynamic from "next/dynamic";
const ChatWidget = dynamic(() => import("./chat-widget"), { ssr: false });Vanilla JS in SSR — guard with typeof window !== "undefined":
if (typeof window !== "undefined") {
const { init } = await import("@masheev/embed-sdk/js");
init({ inboxId: "YOUR_INBOX_ID" });
}Widget Not Appearing After SPA Navigation
The widget initializes once on init(). In SPAs, if you unmount and remount the component, the React hook handles this automatically (singleton per inboxId).
If using vanilla JS, call destroy() before reinitializing:
import { destroy, init } from "@masheev/embed-sdk/js";
// On route change
destroy();
init({ inboxId: "YOUR_INBOX_ID" });CSP Header Configuration
If your site uses Content-Security-Policy headers, add these directives:
script-src 'self' https://cdn.masheev.com;
frame-src 'self' https://app.masheev.com;
connect-src 'self' https://api.masheev.com wss://api.masheev.com;z-index Conflicts
The widget uses z-index: 2147483647 (max). If another element overlaps:
/* Override the widget container z-index */
#masheev-widget-container {
z-index: 999999 !important;
}Cross-Origin Cookie Issues
The widget iframe runs on app.masheev.com. If third-party cookies are blocked:
- Sessions use the session token (Authorization header), not cookies
- No cookie issues in modern browsers — the SDK uses
postMessagefor all communication
GDPR-Compliant Deferred Loading
Load the widget only after the user consents to cookies/data processing:
// Wait for consent
cookieConsent.on("accept", () => {
import("@masheev/embed-sdk/js").then(({ init }) => {
init({
inboxId: "YOUR_INBOX_ID",
requireConsent: true, // Shows consent prompt in widget too
privacyUrl: "https://myapp.com/privacy",
});
});
});Widget Not Connecting / Infinite Loading
- Check
inboxIdis correct (find it in Dashboard > Inboxes) - Check the inbox status is
active(notpausedordisabled) - Check browser console for errors (enable
debug: truein config) - Verify your domain is not blocked by the inbox CORS settings
- Check if a content blocker or ad blocker is intercepting requests
Embedded Mode Not Rendering
The container element must exist in the DOM before init() is called:
// Wrong — element doesn't exist yet
init({ inboxId: "...", mode: "embedded", containerId: "chat" });
// Right — wait for DOM
document.addEventListener("DOMContentLoaded", () => {
init({ inboxId: "...", mode: "embedded", containerId: "chat" });
});For React, use the containerRef from the hook:
const { containerRef } = useMasheev({ inboxId: "...", mode: "embedded" });
return <div ref={containerRef} style={{ height: 500 }} />;Widget Theme Not Following the Page Toggle
The widget's light/dark doesn't update when the host page's theme changes.
Common causes, in order of likelihood:
You're relying on
colorScheme: "auto"but your toggle sets an explicit.lightclass."auto"infers the theme from the DOM. Older@masheev/embed-sdkonly checked for.darkand otherwise fell back toprefers-color-scheme, so choosing light while the OS was dark left the widget dark. Fixed in newer builds (now also honors.light/data-theme). Better: drive it explicitly — callupdateColorScheme(isDark ? "dark" : "light")from your resolved theme state (see "Color Scheme" in SKILL.md). This avoids the DOM heuristic entirely.The host page bundle is stale. The parent-page SDK (
setupDarkModeSync/updateColorScheme) is bundled into your site at build time. If theme sync was added after your last deploy, the deployed page won't send updates even though the widget iframe handles them. Rebuild and redeploy the host page.The widget iframe host is stale. The receiving side lives in the widget app. If the host page sends
updateColorScheme(verify by posting it to the iframe manually) but the widget ignores it, the iframe deployment predates the handler.
Quick bisection: in the page console, post the message the SDK would send straight to the iframe. If the widget flips, the iframe is fine and the problem is the parent not sending:
document.querySelector('iframe[title="Masheev Chat Widget"]')
.contentWindow.postMessage({ type: "updateColorScheme", payload: { colorScheme: "dark" } }, "*");Theme Passed in init() Has No Effect
The theme saved on the inbox in the Masheev dashboard takes precedence over the theme
object in your embed code. If the inbox has an appearance saved, that is what visitors see
and the SDK theme is ignored.
To change the look, either edit the inbox's appearance in the dashboard, or clear the saved theme there so the SDK value applies. Note this is deliberate: it keeps embed code from overriding what the account owner configured.
Custom Font Not Applying
theme.fontFamily only resolves against fonts already installed on the visitor's device,
plus the generic families (sans-serif, serif, monospace). The widget runs in an iframe
that does not load web fonts, so a @font-face or Google Fonts family on the host page is
not available inside it and the widget falls back to the system stack.
The value is also sanitized before use — url(), braces and semicolons are stripped — so a
font stack containing them will be trimmed rather than applied.
Widget Never Appears in Production (Turnstile / CSP)
In production, POST /api/widget/session requires a Cloudflare Turnstile token and rejects a
request without one as 403 Verification required. The widget waits for the invisible
challenge to resolve before creating a session, and will not send an unverified request.
The challenge is served from https://challenges.cloudflare.com. If the host page sends a
Content Security Policy, that origin must be allowed in both directives:
Content-Security-Policy: script-src https://challenges.cloudflare.com; frame-src https://challenges.cloudflare.comIf the challenge cannot load — blocked by CSP, blocked by a privacy extension or ad blocker,
a missing VITE_TURNSTILE_SITE_KEY in the widget build, or a TURNSTILE_SECRET_KEY on the
API that does not match the site key — the widget treats it as a startup failure, not a
message failure. Visitors see nothing at all while it retries quietly in the background,
because a broken composer is worse than no widget.
To see the cause, open the page on a development host or add debug: true to the embed
config (or ?masheev_debug=1 to the URL). The widget then renders a card naming the
problem, and the same diagnosis is always written to the browser console.