> ## Documentation Index
> Fetch the complete documentation index at: https://humain.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Drop-in widget

> Add a floating chat widget to any webpage with a single script tag. No build step, no framework required.

↑ Live preview — click to open

The drop-in widget is a self-contained script that injects a floating chat button into any webpage.
Click the preview above to see exactly what your users will see before reading a line of code.

## Installation

Paste these two tags before `</body>` in your HTML:

```html theme={null}
<script src="https://cdn.humain.ai/widget.js"></script>
<script>
  HumainWidget.init({
    credential: "hk_live_your_credential_here",
    position: "bottom-right",
    theme: "auto",
  })
</script>
```

The widget loads asynchronously and does not block your page render.

> [!TIP]
>
> During development, issue an **`hk_test_`** credential from the admin panel instead of a live
> `hk_live_` one. Sandbox is a property of the credential, not a different base URL — you call
> the same `https://api.humain.ai` host either way. Sandbox sessions don't consume production
> LLM credits and aren't billed. See [Sandbox mode](https://humain.mintlify.site/concepts/sandbox-mode.md).

> [!WARNING]
>
> **Never expose live credentials in client-side code.** Your `hk_live_…` token is a long-lived
> secret. In browser environments, either proxy API calls through your own server or issue an
> `hk_test_…` (sandbox) credential instead for public-facing demos. Treat it like a password.

> [accordion] Install via npm (module bundlers)
>
> If you are using a bundler (webpack, Vite, Rollup), install the npm package instead of the CDN
> script and call `init()` in your entry point:
>
> ```bash npm theme={null}
> npm install @humain/kiosk-js
> ```
>
> ```bash yarn theme={null}
> yarn add @humain/kiosk-js
> ```
>
> ```bash pnpm theme={null}
> pnpm add @humain/kiosk-js
> ```
>
> ```javascript theme={null}
> import { HumainWidget } from "@humain/kiosk-js/widget"
>
> HumainWidget.init({
>   credential: "hk_live_your_credential_here",
>   position: "bottom-right",
>   theme: "auto",
> })
> ```

## Configuration options

> [!TIP]
>
> Prefer a visual workflow? The [Widget Interface Builder](https://humain.mintlify.site/web/widget-builder.md) lets you configure
> every option below against a live preview and copies out ready-to-paste install code.

| Option | Type | Default | Description |
| - | - | - | - |
| `credential` | `string` | **required** | Your device credential token (`hk_live_…`) |
| `mode` | `"sandbox"` \| `"live"` | `"live"` | Environment — use `"sandbox"` during development |
| `position` | `"bottom-right"` \| `"bottom-left"` | `"bottom-right"` | Corner where the widget appears |
| `theme` | `"light"` \| `"dark"` \| `"auto"` | `"auto"` | Colour scheme — `"auto"` follows the OS preference |
| `primaryColor` | `string` | `"#0E50BD"` | Accent colour used for the FAB and message bubbles (hex) |
| `title` | `string` | `"Kiosk"` | Text shown in the widget header |
| `placeholder` | `string` | `"Type a message…"` | Input field placeholder text |
| `initialMessage` | `string` | — | Message displayed automatically when the widget first opens |
| `zIndex` | `number` | `9999` | CSS `z-index` of the widget — increase if other elements overlap it |
| `preferredLanguage` | `string` | — | BCP-47 code for all sessions opened from this widget. Overrides browser language detection |
| `languageSelector` | `{ enabled: boolean, languages: Array<{ code, label }> }` | — | Show a language picker before the first message is sent |
| `showDisclosure` | `boolean` | `true` | Show the AI disclosure banner at the top of the chat panel — required by the EU AI Act for public deployments |

## Programmatic control

Use the `HumainWidget` object to open, close, or destroy the widget from your own code:

```javascript theme={null}
// Open the chat window (e.g. from your own CTA button)
HumainWidget.open()

// Close the chat window
HumainWidget.close()

// Remove the widget and all its DOM elements entirely
HumainWidget.destroy()
```

```javascript theme={null}
// Example: open the widget when the user clicks a custom button
document.getElementById("chat-btn").addEventListener("click", () => {
  HumainWidget.open()
})
```

## Event callbacks

Pass callbacks to `HumainWidget.init()` to react to user interactions:

```javascript theme={null}
HumainWidget.init({
  credential: "hk_live_your_credential_here",
  onOpen:    () => analytics.track("widget_opened"),
  onClose:   () => analytics.track("widget_closed"),
  onMessage: (msg)  => console.log("User said:", msg),
  onResponse:(resp) => console.log("AI replied:", resp),
})
```

| Callback | Signature | When it fires |
| - | - | - |
| `onOpen` | `() => void` | User opens the chat window |
| `onClose` | `() => void` | User closes the chat window |
| `onMessage` | `(message: string) => void` | User sends a message |
| `onResponse` | `(response: string) => void` | AI response is fully received |

## Advanced topics

> [accordion] Content Security Policy
>
> If your site uses a `Content-Security-Policy` header, add the following directives to allow
> the widget to load and communicate:
>
> ```http theme={null}
> Content-Security-Policy:
>   script-src 'self' https://cdn.humain.ai;
>   connect-src 'self' https://api.humain.ai wss://api.humain.ai;
>   frame-src 'none';
> ```
>
> There is no separate sandbox host to allow-list — sandbox vs. live is determined by which
> credential (`hk_test_` vs `hk_live_`) the widget is configured with, not a different URL.
>
> The widget does not use iframes or inline `eval()`. If you use a strict `script-src` policy,
> you may need to add a nonce or hash for the inline `<script>` that calls `HumainWidget.init()`.

> [accordion] Loading the script asynchronously
>
> For maximum page performance, load the widget script asynchronously and defer initialisation
> until after the page is interactive:
>
> ```html theme={null}
> <script>
>   window.addEventListener("DOMContentLoaded", function () {
>     var s = document.createElement("script")
>     s.src = "https://cdn.humain.ai/widget.js"
>     s.onload = function () {
>       HumainWidget.init({
>         credential: "hk_live_your_credential_here",
>       })
>     }
>     document.head.appendChild(s)
>   })
> </script>
> ```

> [accordion] Multiple kiosks on one page
>
> You can render multiple independent widget instances with different credentials (e.g. one for
> support and one for sales). Use `HumainWidget.create()` instead of `HumainWidget.init()`:
>
> ```javascript theme={null}
> const supportWidget = HumainWidget.create({
>   credential: "hk_live_SUPPORT_TOKEN",
>   position: "bottom-right",
>   title: "Support",
> })
>
> const salesWidget = HumainWidget.create({
>   credential: "hk_live_SALES_TOKEN",
>   position: "bottom-left",
>   title: "Sales",
> })
> ```
>
> Each instance is independent and can be controlled separately via the returned object.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.