Install the SDK
Add the Mojar chat widget to any website using the loader script or an npm package.
There are two ways to add the Mojar chat widget to a site. The loader script is the confirmed, production-ready path. The @mojar/sdk npm packages are the alternative for bundled JavaScript applications.
Prerequisites
Before adding the widget you need:
- An agent UUID — found on the Website Embed tab of your agent in mojar.ai.
- A domain UUID — generated when you register your site's domain on the same tab.
See embed widget — domains for how to register a domain and retrieve both UUIDs.
Option 1 — Loader script (recommended)
Add a single <script> tag to your HTML. The script self-initialises; no additional JavaScript is required.
<script
src="https://app.mojar.ai/widget-mojar-loader.js"
data-agentid="YOUR_AGENT_UUID"
data-domainuuid="YOUR_DOMAIN_UUID"
></script>The loader:
- Validates the agent and domain by calling
/api/embed/initiate-sessionon the Mojar host. - Injects an animated toggle button into the page.
- Creates an iframe pointing to the embed chat route when the button is first clicked (lazy load).
- Handles token refresh silently in the background.
You can place the <script> tag anywhere in the document. It runs once even if included multiple times.
For full attribute reference (button position, theme, colors, and more) see embed widget — configuration.
For the full technical breakdown of boot sequence, JS API, and postMessage events see loader script.
Option 2 — npm packages
Two npm packages are available for bundled apps:
| Package | Use case |
|---|---|
@mojar/sdk | Framework-agnostic TypeScript — any bundled app |
@mojar/sdk-react | React ≥18 bindings that wrap @mojar/sdk |
npm install @mojar/sdk
# or for React
npm install @mojar/sdk-reactIf you only need the widget on a static site or a server-rendered app, the loader script requires zero build tooling and is the simpler choice.