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.

Initial setup time: About 5 minutes. Have a MuChat agent ready to answer questions before you start.

What You Can Do

Quick Start Guide

Get Your Installation Code

  1. Open the MuChat dashboard.
  2. Open your agent and go to Deploy.
  3. Click Manage on the Chat Widget card.
  4. Select Deploy above the preview, then choose Website widget.
  5. Open the HTML, React.js, or Next.js tab for your setup and copy the code.
MuChat's Website widget installation panel with HTML, React.js, and Next.js tabs and the copy button

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>

Install the widget once. In React and Next.js, place the installation component in the root or shared layout so navigating between pages does not add another script.

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.

If the bubble appears and MuChat responds to your message, initial setup is complete.

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 in user_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.

Best Practices

Performance Optimization

Load the script asynchronously. The dashboard's HTML code sets g.async = true; the React example also loads asynchronously, and the Next.js example uses afterInteractive.

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

Security Considerations

Never put the identity signing secret in browser code. Create JWTs on your server and send only the signed token for that user to the widget. The installation code's websiteToken is a public widget identifier and does not replace user authentication.

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.

Your site's frame-src controls which frames it can load. A frame-ancestors error concerns permission to embed the conversation: add your site's origin, with the correct protocol and port, to Allowed Domains in the MuChat dashboard and save. MuChat's allowed domains setting does not change your website's CSP.

Check scripts and other restrictions

  • sdk.js is blocked: With a host allowlist policy, allow https://widget.mu.chat in script-src. If script-src-elem is 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, or connect-src errors: 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 need connect-src permission for https://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

What's Next?

MuChat documentation

On this page