Getting Started
Chat Bubble Installation
Install the MuChat floating widget in HTML, React, or Next.js, with widget controls, user identification, and display settings.
Add MuChat's installation code to display a floating chat bubble on your website. Visitors can chat without leaving the page. Use the ready-made widget or connect its behavior to your application with JavaScript.
What You Can Do
- Simple installation: Add the code to your site to display a chat bubble.
- User identification: Introduce signed-in website users to MuChat with a JWT signed on your server.
- Widget controls: Open and close the chat window from your site's buttons.
- Widget events: Receive notifications when the widget is ready, opened, or closed.
- Appearance and language: Set the language, theme, and bubble position with JavaScript; configure colors, avatars, and initial messages in the dashboard.
- Custom actions: Use AI Actions to connect MuChat to your business APIs during conversations.
Quick Start Guide
Get Your Installation Code
- Open the MuChat dashboard.
- Open your agent and go to Deploy.
- Click Manage on the Chat Widget card.
- Select Deploy above the preview, then choose Website widget.
- Open the HTML, React.js, or Next.js tab for your setup and copy the code.

Add to Your Website
Use the dashboard's installation code or the example for your application below. Replace YOUR_WEBSITE_TOKEN with the websiteToken value from the dashboard's installation code. This identifies the widget; it is not your agent ID or Chat API key.
Place the code in your site's HTML, before the closing </body> tag.
<script>
(function (d, t) {
var BASE_URL = "https://widget.mu.chat";
var g = d.createElement(t);
var s = d.getElementsByTagName(t)[0];
g.src = BASE_URL + "/sdk.js";
g.async = true;
s.parentNode.insertBefore(g, s);
g.onload = function () {
window.muchatSDK.run({
websiteToken: "YOUR_WEBSITE_TOKEN",
baseUrl: BASE_URL
});
};
})(document, "script");
</script>Render this component once at the root of your application. It initializes the widget after the script loads.
import { useEffect } from "react";
export default function MuchatWidget() {
useEffect(() => {
const start = () => window.muchatSDK.run({
websiteToken: "YOUR_WEBSITE_TOKEN",
baseUrl: "https://widget.mu.chat"
});
if (window.muchatSDK) {
start();
return;
}
let script = document.getElementById("muchat-sdk");
if (!script) {
script = document.createElement("script");
script.id = "muchat-sdk";
script.src = "https://widget.mu.chat/sdk.js";
script.async = true;
}
script.addEventListener("load", start);
if (!script.isConnected) document.body.appendChild(script);
return () => script.removeEventListener("load", start);
}, []);
return null;
}Include this Client Component in your shared application layout. onReady initializes MuChat after the script loads.
"use client";
import Script from "next/script";
export default function MuchatWidget() {
return (
<Script
id="muchat-sdk"
src="https://widget.mu.chat/sdk.js"
strategy="afterInteractive"
onReady={() => {
window.muchatSDK.run({
websiteToken: "YOUR_WEBSITE_TOKEN",
baseUrl: "https://widget.mu.chat"
});
}}
/>
);
}Test Integration
Open your website, click the chat bubble, and ask a question covered by your knowledge base. Check the bubble, window controls, and responses on desktop and mobile. The Chat Widget channel must also be active in the dashboard.
If your site has a content security policy, check the CSP settings too; the policy can block the script or conversation frame.
Add Advanced Features (Optional)
After installation, connect your site's buttons to the widget, identify signed-in users, or listen for events. This example runs each time the chat window opens:
window.addEventListener("muchat:opened", () => {
console.log("MuChat opened");
});Listen for events on window; widget control methods are available on window.$muchat.
JavaScript Embed Core Features
Identify users who are signed in to your website
If your website has user accounts, connect each user's verified identity to their conversation:
- In the Website widget installation panel, open Identity verification and obtain the identity signing secret.
- On your server, create a JWT for the signed-in user with
HS256. Put their identifier inuser_id; include their name, email, and an expiration time as shown in the dashboard example. - After running the installation code and obtaining the token from your server, pass it to the widget with
window.$muchat.setUser(userJwt). - To restrict chat to signed-in users, first connect user identification, then enable Allow access only to authenticated users and click Save. The bubble and chat window remain hidden until the identity is verified.
Keep the signing secret on your server. The token sent to the browser must be signed for that user.
Connect your site's behavior to the widget's state
Register listeners with window.addEventListener:
| Event | When it fires |
|---|---|
muchat:ready | After the widget's initial setup and configuration have loaded |
muchat:opened | When the chat window opens |
muchat:closed | When the chat window closes |
Loading sdk.js is different from having a fully ready widget. Register the muchat:ready listener before calling muchatSDK.run so you receive the initial event. Operations that need chat readiness, such as sendMessage, must run after this event.
Control chat from your site's buttons
After initializing the widget, call these methods from a Help or Support button's click handler:
| Method | Purpose |
|---|---|
window.$muchat.open() | Open the chat window |
window.$muchat.close() | Close the chat window |
window.$muchat.toggle() | Switch between open and closed |
window.$muchat.sendMessage("Hello") | Send a real message as the user and open chat; call after muchat:ready |
Use window.$muchat.toggleBubbleVisibility("show") and window.$muchat.toggleBubbleVisibility("hide") to show or hide the bubble itself. If you hide it, provide a clearly labeled button on your site to open chat.
Match the widget to your website
Manage the Chat Widget card under Deploy to configure its color, avatar, welcome messages, suggested questions, screen-edge spacing, and mobile visibility.
To keep the language, theme, and bubble position in sync with your application, call these methods after initializing the widget:
window.$muchat.setLocale("en");
window.$muchat.setColorScheme("dark");
window.$muchat.setPosition("right");Supported languages are fa, en, and ar; themes are light and dark, and bubble positions are left and right.
Best Practices
Performance Optimization
Keep installation code in a shared file or layout. In single-page applications, do not insert another script on each route change; one installation covers the application.
User Experience
- Test bubble visibility and opening and closing chat on mobile devices.
- Adjust the bubble's position and spacing so it does not overlap bottom navigation, the shopping cart, or primary site controls.
- Check mobile visibility settings and keep initial messages short and readable.
- Use a
buttonelement with a clear label, such as "Chat with support," for custom launchers. - Test opening and closing chat and keyboard navigation on your website.
- Check custom color contrast and text readability, and test the chat experience with a screen reader.
- The SDK tracks the current page URL and title as visitors navigate; single-page route changes do not need another installation.
- Identify signed-in users with a JWT signed on your server.
- Avoid resetting chat on every page change so visitors can continue their conversations.
Security Considerations
You can also configure Allowed Domains in the installation panel. Enter one origin, including its protocol, per line, such as https://example.com. A pattern such as https://*.example.com can cover subdomains. Click Save after changing settings.
Content Security Policy (CSP)
The floating widget also loads its conversation inside an iframe. If the browser console reports Content Security Policy or Refused to frame for https://widget.mu.chat, check the directive named in the error.
Allow the conversation frame on your website
For a frame-src violation, ask your developer or hosting provider to add https://widget.mu.chat to frame-src in your website's CSP. The policy may come from your server, CDN, or security plugin. For example, if the current value is only 'self', change that directive to:
frame-src 'self' https://widget.mu.chat;This is one directive, not a complete policy: preserve your other directives and existing allowed origins. If the current value is frame-src 'none', that restriction must change to allow the widget. When frame-src is absent, browsers fall back to child-src, then default-src; preserve your existing frame origins when adding an explicit directive. See the frame-src reference.
Check scripts and other restrictions
sdk.jsis blocked: With a host allowlist policy, allowhttps://widget.mu.chatinscript-src. Ifscript-src-elemis defined, check permission there too; it takes precedence for script elements. See the script-src-elem reference.- The inline HTML installation code is blocked: Allowing the domain does not authorize inline scripts. Have your developer use a nonce or hash that matches the site's policy, or move the initialization code into an allowed JavaScript file. With
strict-dynamic, adding a domain alone is insufficient; the SDK must also load through the trusted script chain. See the script-src guide. style-src,img-src, orconnect-srcerrors: Identify the blocked URL, directive, and document. The SDK adds bubble styles to the host page; allowing a frame origin does not fix blocked inline styles. Notification audio requests may also needconnect-srcpermission forhttps://widget.mu.chat. Inspect errors inside the frame in that frame's console and share the exact error with your developer.
Keep CSP enabled and review the specific resource and directive instead of allowing every origin with *.
Verify the change
In Network, inspect the main website document's Content-Security-Policy response header. Also check the HTML for a meta tag with http-equiv="Content-Security-Policy". Every enforced policy must allow the resource; another header or meta tag cannot relax an existing policy. Changing only Content-Security-Policy-Report-Only does not remove an enforced restriction. See multiple content security policies.
After saving, refresh the relevant website or CDN cache and reload with developer tools' Disable cache enabled. Verify that sdk.js and the widget frame load without blocking errors, the bubble appears, the conversation opens, and a test message receives a reply.
Troubleshooting
- Compare
websiteTokenwith the same widget's installation code in the dashboard. Do not substitute an agent ID or API key. - Use developer tools' Console and Network panels to check
https://widget.mu.chat/sdk.jsand the widget frame. For CSP errors, follow the content security policy guide. - Check that the Chat Widget channel is active. To show the built-in bubble, set Widget Launcher to default. Mobile widget visibility must also be enabled for mobile visitors.
- If Allowed Domains is restricted, add your site's origin with the correct protocol and port, then save; for example,
http://localhost:3000for local testing. - If access is restricted to authenticated users, the widget stays hidden until a valid JWT is verified. Check your
setUserintegration. - If Widget Launcher is custom, or your code hides the bubble with
toggleBubbleVisibility("hide"), check your custom button for opening chat.
- Check the installation code on the affected published page. If no
sdk.jsrequest appears, inspect the installation, earlier JavaScript errors, consent management, and tools that delay scripts. - Test in a browser without blocking extensions. An error such as
ERR_BLOCKED_BY_CLIENTcan come from an extension or browser filter; investigate DNS, TLS, or unsuccessful network responses separately. - If the issue started after a code or settings change, refresh the site and CDN cache. In WordPress, check JavaScript combining, minification, and delay settings so the SDK loads before initialization runs.
- If consent management gates the script, test loading after the visitor's permitted choice. Check desktop and mobile visibility separately.
- Confirm that
muchatSDK.runran after the script loaded and thatwindow.$muchatis available. - Check event names and register them with
window.addEventListener, for examplemuchat:opened. - Register the
muchat:readylistener before initializing the widget. Wait for readiness before sending messages from code. - Check the browser console and Network panel. React installation code must run in the browser; in Next.js, a component with
onReadymust be a Client Component.
What's Next?
Customize Appearance
Match the color, avatar, and initial messages to your brand.
Response Settings
Configure MuChat's model, instructions, and response accuracy.
Custom Actions
Connect to your business APIs to answer questions and carry out tasks.
Website Integration Options
Learn about iframes for chat in a fixed section of your page.