Website Widgets
Embed voice agents on your website with customizable widgets
Embed your voice agent on any website so visitors can start a voice conversation directly from the browser. The Widgets tab provides embed codes, customization options, and domain security settings.
The Callback Widget works very differently from the widgets on this page — instead of starting a browser voice call, it collects the visitor's phone number and has your agent dial them back. See the dedicated Callback Widget page.
Widget Types
Hanc.AI offers four in-browser widget types, plus a separate Callback Widget for phone callbacks:
| Widget | Tag Name | Description | Best For |
|---|---|---|---|
| Floating Widget | hanc-ai-floating-call | Orb button that floats over your page | Always-visible call-to-action |
| Pill Widget | hanc-ai-pill-call | Compact pill-shaped button placed inline in your content | Minimal footprint inside an existing layout |
| Pill Floating Widget | hanc-ai-pill-floating-call | Same compact pill shape as Pill, but floats with the page like the Floating widget | When you want a pill aesthetic that follows the visitor as they scroll |
| Inline Widget | hanc-ai-inline-call | Full-size call button embedded in page content | Dedicated "Talk to Us" sections |
| Callback Widget | hanc-ai-callback | Phone-number form; agent calls the visitor back | Lead-gen pages, high-intent landing pages — see Callback Widget |
In the dashboard, the Pill Floating widget is the Pill snippet switched to Float. Its tag is hanc-ai-pill-floating-call — check that the copied snippet uses exactly this tag.
See example on the Widgets tab opens a live demo page of the agent's widget.
Common Attributes
All widget types support these core attributes:
| Attribute | Required | Description | Default |
|---|---|---|---|
agent-id | Yes | Your agent's unique identifier | — |
voice-service-url | No | Override the voice service URL | Auto-detected |
api-base-url | No | Override the API base URL | Auto-detected |
support-session-token | No | A short-lived token your server issues for the signed-in user, passed to your MCP servers. Floating, Pill, Pill Floating and Inline only — see Identifying a Signed-In User | — |
Display Attributes
| Attribute | Description | Values | Default |
|---|---|---|---|
position | Widget position on the page | bottom-right, bottom-left, top-right, top-left, static | bottom-right |
size | Widget size in pixels | Number | 120 (Floating), 370 (Inline; scales down on small screens) |
orb-size | Orb diameter in the Pill widgets | Number | 48 |
theme | Color theme name | See Color Themes | default |
Button Text Attributes
| Attribute | Description | Default |
|---|---|---|
button-start-text | Text shown on the idle button | "Call" (Floating), "Start Call" (Inline), "Talk to AI Agent" (Pill) |
button-connecting-text | Text shown while connecting | "Connecting..." |
button-end-text | Text shown during an active call | "End call" (Pill) |
Orb Attributes
The 3D orb reacts to the voice. The most useful knobs:
| Attribute | Description | Default |
|---|---|---|
glow-intensity | Glow strength, 0–2 | 0.8 |
audio-reactivity | How strongly the orb reacts to audio | 3.0 |
theme-mode | auto (follows the system), dark or light | auto |
The package README lists the rest (morph-strength, noise-speed, rotation-speed and others).
Terms Attributes
| Attribute | Description | Default |
|---|---|---|
terms-enabled | Enable consent dialog before call | false |
terms-content | Markdown-formatted consent text | "" |
terms-url | Link to your Terms & Conditions page | "https://hanc.ai/terms" |
privacy-url | Link to your Privacy Policy page | "https://hanc.ai/privacy" |
Terms attributes set on the HTML element are overridden by the agent's widget settings fetched from the API, unless skip-fetch is set to true.
Sound Attributes
| Attribute | Description | Default |
|---|---|---|
sound-enabled | Enable call start/end sounds | true |
sound-volume | Sound effect volume | 0.25 |
sound-preset | Sound preset identifier | "1" |
Color Themes
Customize widget appearance with 11 built-in color themes:
| Theme | Value |
|---|---|
| Default | default |
| Purple | purple |
| Blue | blue |
| Cyan | cyan |
| Emerald | emerald |
| Amber | amber |
| Tangerine | tangerine |
| Rose | rose |
| Ember | ember |
| Black | black |
| White | white |
Each theme has both dark and light variants. Set the theme via the theme attribute in the embed code, or configure it in the agent's widget settings.
Embed Examples
Floating Widget
<hanc-ai-floating-call agent-id="YOUR_AGENT_ID"></hanc-ai-floating-call>
<script src="https://unpkg.com/hanc-webrtc-widgets@2.11.0/dist/hanc-webrtc-widgets.umd.js" integrity="sha384-67jqLMGYjzUXiBfSD/Kyd2bcyWxLVCzOQzNPIwKfxqoaDbmnYYGr08hNPYp1+11f" crossorigin="anonymous" async></script>
Floating Widget with Theme and Position
<hanc-ai-floating-call
agent-id="YOUR_AGENT_ID"
theme="emerald"
position="bottom-left"
size="140"
></hanc-ai-floating-call>
<script src="https://unpkg.com/hanc-webrtc-widgets@2.11.0/dist/hanc-webrtc-widgets.umd.js" integrity="sha384-67jqLMGYjzUXiBfSD/Kyd2bcyWxLVCzOQzNPIwKfxqoaDbmnYYGr08hNPYp1+11f" crossorigin="anonymous" async></script>
Pill Widget
<hanc-ai-pill-call agent-id="YOUR_AGENT_ID"></hanc-ai-pill-call>
<script src="https://unpkg.com/hanc-webrtc-widgets@2.11.0/dist/hanc-webrtc-widgets.umd.js" integrity="sha384-67jqLMGYjzUXiBfSD/Kyd2bcyWxLVCzOQzNPIwKfxqoaDbmnYYGr08hNPYp1+11f" crossorigin="anonymous" async></script>
Inline Widget
<hanc-ai-inline-call agent-id="YOUR_AGENT_ID"></hanc-ai-inline-call>
<script src="https://unpkg.com/hanc-webrtc-widgets@2.11.0/dist/hanc-webrtc-widgets.umd.js" integrity="sha384-67jqLMGYjzUXiBfSD/Kyd2bcyWxLVCzOQzNPIwKfxqoaDbmnYYGr08hNPYp1+11f" crossorigin="anonymous" async></script>
Pill Floating Widget
<hanc-ai-pill-floating-call agent-id="YOUR_AGENT_ID"></hanc-ai-pill-floating-call>
<script src="https://unpkg.com/hanc-webrtc-widgets@2.11.0/dist/hanc-webrtc-widgets.umd.js" integrity="sha384-67jqLMGYjzUXiBfSD/Kyd2bcyWxLVCzOQzNPIwKfxqoaDbmnYYGr08hNPYp1+11f" crossorigin="anonymous" async></script>
Frameworks and Apps
The widgets are standard web components, so they work in any stack. A few notes:
| Stack | What to do |
|---|---|
| React below 19 | Wrap each widget with createComponent from @lit/react (npm install @lit/react hanc-webrtc-widgets) so props and events pass through. React 19 handles custom elements natively |
| Next.js | Load the widget on the client only: dynamic(..., { ssr: false }) around the @lit/react wrapper |
| Vue | Import hanc-webrtc-widgets in onMounted to register the components, then use the tags in the template |
| iOS / Android WebView | The app must grant the WebView microphone access and allow WebRTC; otherwise the call cannot start |
Full examples for each stack are in the package README on npm.
The snippets on this page load a fixed release (2.11.0) with an integrity hash, so the browser refuses the script if the file has been changed. To move to a newer release, change the version in the URL and replace the integrity value with that release's hash, for example from curl -sL <script URL> | openssl dgst -sha384 -binary | openssl base64 -A.
Widget Events
Widgets emit events that you can listen for in JavaScript:
| Event | Description |
|---|---|
status-changed | Fired when the call status changes |
connecting | Call is being established |
connected | Call is active |
idle | No active call |
error | An error occurred |
audio-track | Remote audio track received (for visualization) |
local-audio-track | Local microphone audio track (for visualization) |
microphone-enabled | Microphone was enabled |
microphone-disabled | Microphone was disabled |
call-start | Fired when a call starts successfully |
call-end | Fired when the call ends |
Example: Listening for Events
const widget = document.querySelector('hanc-ai-floating-call');
widget.addEventListener('call-start', () => {
console.log('Call started');
});
widget.addEventListener('call-end', () => {
console.log('Call ended');
});
Letting the Agent Open Pages
The Agent navigation block on the Widgets tab shows the ready-made handler code. During a browser call the agent can ask your site to open a page — "let me show you the pricing" — and the visitor sees it happen while they keep talking.
Your page stays in charge. The agent sends a request; your code decides what it means. Opening a URL, switching a tab, scrolling to a section and expanding an accordion are all valid answers.
This takes three steps, and none of them work alone.
Step 1 — Tell the agent which pages exist
The agent cannot see your site map. It only ever asks for a path you gave it, so list them in the agent's prompt or knowledge base:
Pages on our site:
/pricing — plans and prices
/contact — contact form and phone number
/product/crm — the CRM
Skip this step and the agent has nothing to ask for, so it never tries.
Step 2 — Handle the request on your page
Add this once, anywhere after the widget script. The event travels up through the page, so document is a fine place to listen:
<script>
document.addEventListener('agent-command', (event) => {
const { type, payload } = event.detail;
if (type === 'navigate') {
// Single-page app: route without reloading — the call keeps running.
router.push(payload.path);
// Classic site: open a second tab, so this one (and the call) survives.
// window.open(payload.path, '_blank');
event.preventDefault(); // ← tells the agent you handled it
}
});
</script>
The call lives in this page. window.location.href = … unloads the document and the conversation goes with it — the visitor is cut off mid-sentence. Route client-side if you have a router, or open the page in a new tab. There is no reconnect: nothing survives a reload.
preventDefault() is not optionalIt is the only way to say "I handled it". Leave it out and the agent is told the site does not support navigation: it stops trying for the rest of the call and falls back to describing where to click. Nothing appears in the browser console — the page simply looks like it ignored the request, because it did.
Step 3 — Try it
Call your agent from the site and ask for a page by name. Two things should happen: the page opens, and the agent says something like "here are the prices" rather than "you can find them in the menu".
Answering the agent with data
Some commands are questions rather than instructions. They arrive the same way, but you reply with respond():
| Command | The agent is asking | You reply with |
|---|---|---|
navigate | "open this path" | nothing — just preventDefault() |
page_context | "what is the visitor looking at?" | anything useful: path, title, product |
cart_state | "what is in their basket?" | items, totals, currency |
<script>
document.addEventListener('agent-command', (event) => {
const { type, respond } = event.detail;
if (type === 'page_context') {
event.preventDefault();
respond({ path: location.pathname, title: document.title });
}
});
</script>
You have about a second to answer after preventDefault(), so an await is fine but a slow API call is not. Answer with what you already have.
What the agent may and may not ask for
- Paths on your own site only. A path must start with
/. Anything that could leave your domain —//evil.com,https://…, backslashes — is refused before it reaches your page. An agent cannot send your visitors somewhere else. - Browser calls only. There is no page to open on a phone call, so these commands do not exist there.
- One refusal is enough. If your page does not confirm the first request, the agent stops asking for the rest of the call. It will not keep trying, and — importantly — it will not tell the visitor it opened something it did not.
Log every command before you filter it: document.addEventListener('agent-command', e => console.log(e.detail)). If you see navigate in the console, the agent is doing its part and the missing piece is preventDefault() or your own handler. If you see nothing, the agent was never told the path exists — go back to step 1.
Identifying a Signed-In User
If visitors sign in on your site, the agent can work with their account — orders, bookings, tickets — through your MCP servers. The widget doesn't know who is signed in; your page tells it with a token.
How it works
- Your server issues a separate short-lived token (15 minutes or less, audience set to your MCP server) and your page puts it into the widget attribute
support-session-token. The attribute works on the Floating, Pill, Pill Floating and Inline widgets; the Callback widget doesn't support it. - Hanc passes the token, unchanged, to every MCP connection of the agent in the HTTP header
X-Hanc-Support-Token. - Hanc does not parse, verify or store the token. Your MCP server checks its signature and expiry and decides who the user is.
Every MCP connection of the agent receives this header, including CRM tiles (monday.com, GoHighLevel, CallRail, Kommo). Never pass your site's session token or cookie.
When no one is signed in on the page, or the attribute isn't set, the header simply doesn't arrive — and the agent can still use the tools of your MCP connections. Your MCP server must therefore decide on its own: if X-Hanc-Support-Token is missing or fails verification, refuse any request for account data — return an error, or return only data that is public anyway.
Which token to pass
Don't pass anything a caller could guess or copy and present as their own, such as a plain user ID. Pass something only the issuer can confirm, and on your server ask the issuer who the user is.
| Approach | Can it be forged? | Verdict |
|---|---|---|
| A plain user ID | Trivially | Unacceptable |
| An encrypted user ID | No, but it can be replayed forever | Unacceptable |
| Your login provider's token (JWT) | No, but every MCP connection receives it and can replay it | Unacceptable |
| A one-time, short-lived token issued by your server | No, and it can't be replayed either | Best |
Embedding the widget with a token
Render the token into the page on your server:
<hanc-ai-floating-call
agent-id="YOUR_AGENT_ID"
support-session-token="{{ support_token }}"
></hanc-ai-floating-call>
<script src="https://unpkg.com/hanc-webrtc-widgets@2.11.0/dist/hanc-webrtc-widgets.umd.js" integrity="sha384-67jqLMGYjzUXiBfSD/Kyd2bcyWxLVCzOQzNPIwKfxqoaDbmnYYGr08hNPYp1+11f" crossorigin="anonymous" async></script>
Or set it from JavaScript once the user has signed in, before the call starts:
const res = await fetch('/api/support-token'); // your endpoint, issues a short-lived token
const { token } = await res.json();
document
.querySelector('hanc-ai-floating-call')
.setAttribute('support-session-token', token);
In an iOS or Android app, load the same page in the WebView after sign-in, so the attribute already carries the user's token.
Checking the token in your MCP server
A sketch in Node.js with jose: the account tool reads the header, verifies the token your server issued — signature, issuer, audience and expiry — and refuses when the header is missing or the token is invalid. How a tool handler reaches the HTTP request depends on your MCP framework.
import { createRemoteJWKSet, jwtVerify } from 'jose';
// Public keys of your server that issues support tokens
const JWKS = createRemoteJWKSet(new URL('https://example.com/.well-known/jwks.json'));
async function signedInUser(headers: Record<string, string | undefined>): Promise<string | null> {
const token = headers['x-hanc-support-token'];
if (!token) return null; // nobody signed in on the page
try {
const { payload } = await jwtVerify(token, JWKS, {
issuer: 'https://example.com/',
audience: 'https://mcp.example.com/',
});
return payload.sub ?? null; // your server signed this, so it can be trusted
} catch {
return null; // bad signature or expired
}
}
// An MCP tool that returns account data
async function getMyOrders(headers: Record<string, string | undefined>) {
const userId = await signedInUser(headers);
if (!userId) {
return {
isError: true,
content: [{ type: 'text', text: 'The caller is not signed in. Account data is not available.' }],
};
}
const orders = await db.orders.findByUser(userId);
return { content: [{ type: 'text', text: JSON.stringify(orders) }] };
}
If you issue one-time tokens yourself, replace jwtVerify with a lookup in your own store: find the token, check it hasn't expired or been used, mark it used, and take the user from that record.
Technical Requirements
Widgets require the visitor's browser to support:
- WebGL 2.0 — for rendering
- Web Audio API — for audio processing
- WebRTC — for real-time voice communication
All modern browsers (Chrome, Firefox, Safari, Edge) support these technologies.
Domain Restrictions
Control which websites can embed your agent widget.
Always Allowed Domains
The following domains are always allowed regardless of configuration:
hanc.ai(and subdomains)localhost
Allow All Domains
By default, your widget can be embedded on any website. Toggle "Allow all domains" in widget settings to restrict this.
Restrict to Specific Domains
When restricted, add each domain that should be allowed:
- Enter domain names without
https://(e.g.,example.com) - Subdomains need separate entries (e.g.,
www.example.com,shop.example.com) - Ports can be specified (e.g.,
localhost:3000) - Maximum 50 domains can be whitelisted
The list stops other websites from embedding your widget in a browser, but it is not access control: a script outside a browser can still reach the agent. Do not rely on it to protect data — give the agent only the tools and knowledge an anonymous visitor may use, and let your MCP servers check who is calling — see Identifying a Signed-In User.
Terms & Conditions
Enable a consent dialog before callers can start a conversation.
Configuration
| Setting | Description |
|---|---|
| Enable Terms | Toggle terms dialog on/off |
| Terms Content | Markdown-formatted consent text shown to users (max 5,000 characters) |
| Terms URL | Link to your full Terms & Conditions page |
| Privacy URL | Link to your Privacy Policy page |
When enabled:
- Users see a consent dialog before starting a call
- They must click "Agree" to proceed
- Consent is stored locally in the browser
- Reset Consent button clears stored consent for testing
Content Formatting
Terms content supports Markdown formatting:
- Use
####for headings - Use
**bold**for emphasis - Use line breaks for readability
What the Widget Stores in the Browser
The widget keeps a few small values in the visitor's localStorage:
| Key | What it holds |
|---|---|
user_identity | A random ID for the visitor's browser, so repeat calls from the same browser are recognised |
privacy_accepted | That the visitor accepted the Terms & Conditions dialog, so it isn't shown again |
hanc_callback_timestamps | When the visitor last requested callbacks — used to rate-limit the callback form |
No call content is stored in the browser.
Related
- Callback Widget — Phone callbacks for visitors who'd rather not talk in-browser
- Voice Agents Overview
- Settings — Agent settings including widget configuration
- Integrations — API keys and phone number setup