Index of every page on this site: llms.txt
All skills
masheev avatar

/masheev-widget

@21d3a39
by masheevmasheev/skills1 stars
Run it yourself

Use when installing, configuring, or troubleshooting the Masheev chat widget in any web application. Covers adding the chat widget via script tag, npm package (@masheev/embed-sdk), React, Next.js, Vue, and vanilla JavaScript. Handles SSR safety ("window is not defined"), SPA route changes, user identity with HMAC verification, widget positioning, theming (light/dark/auto, colours, fonts, message style), CSP headers, GDPR consent gating, embedded mode, prompt-input mode, and common errors. Use this skill whenever someone asks to "add Masheev", "install the chat widget", "embed Masheev", or mentions @masheev/embed-sdk.

Use this Skill: https://skilld.dev/gh/masheev/skills/masheev-widget

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencestroubleshooting.md

≈1.8k tokens on demand. Your agent reads this file only when SKILL.md points to it.

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 postMessage for 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

  1. Check inboxId is correct (find it in Dashboard > Inboxes)
  2. Check the inbox status is active (not paused or disabled)
  3. Check browser console for errors (enable debug: true in config)
  4. Verify your domain is not blocked by the inbox CORS settings
  5. 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:

  1. You're relying on colorScheme: "auto" but your toggle sets an explicit .light class. "auto" infers the theme from the DOM. Older @masheev/embed-sdk only checked for .dark and otherwise fell back to prefers-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 — call updateColorScheme(isDark ? "dark" : "light") from your resolved theme state (see "Color Scheme" in SKILL.md). This avoids the DOM heuristic entirely.

  2. 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.

  3. 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.com

If 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.

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

1 warning7mo3 checks · Risk SAFE
  • Gen Agent Trust Hub7mo

    This skill provides integration documentation and code samples for the Masheev chat widget. It includes standard installation procedures using official vendor resources, such as npm packages and script tags, and demonstrates secure secret management for user identity verification.

  • Socket7mo

    No alerts

  • Snyk7mo

    Risk: MEDIUM · 2 issues

Signed by skilld at 21d3a39. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 weeks ago.

Activeupdated 3 months ago
metadata
{
  "author": "masheev",
  "version": "0.1.0"
}

README badge

README badge for masheev/skills/masheev-widget