Global Objects
window.chatwootSDK
The main SDK object for initializing the widget.app/javascript/entrypoints/sdk.js:219-221
window.$chatwoot
The widget instance object with all control methods. Available after initialization.app/javascript/entrypoints/sdk.js:58-211
window.chatwootSettings
Configuration object. Must be set before the SDK script loads.Configuration API
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
hideMessageBubble | boolean | false | Hide the chat bubble launcher |
position | string | 'right' | Widget position: 'left' or 'right' |
locale | string | 'en' | Language code (ISO 639-1) |
useBrowserLanguage | boolean | false | Use browser’s language automatically |
type | string | 'standard' | Bubble type: 'standard' or 'expanded_bubble' |
launcherTitle | string | '' | Text shown in expanded bubble |
showPopoutButton | boolean | false | Show button to open chat in new window |
showUnreadMessagesDialog | boolean | true | Show unread message notifications |
widgetStyle | string | 'standard' | Widget style: 'standard' or 'flat' |
darkMode | string | 'light' | Color scheme: 'light', 'dark', or 'auto' |
welcomeTitle | string | '' | Custom welcome message title |
welcomeDescription | string | '' | Custom welcome message description |
availableMessage | string | '' | Custom “agents available” message |
unavailableMessage | string | '' | Custom “agents unavailable” message |
enableFileUpload | boolean | true | Allow file uploads in chat |
enableEmojiPicker | boolean | true | Show emoji picker in chat |
enableEndConversation | boolean | true | Allow users to end conversations |
baseDomain | string | undefined | Domain for cross-subdomain cookies |
app/javascript/entrypoints/sdk.js:50-81
Example: Complete Configuration
Widget Control Methods
toggle(state)
Open or close the widget. Parameters:state(optional):'open','close', or omit to toggle
void
app/javascript/entrypoints/sdk.js:83-85
toggleBubbleVisibility(visibility)
Show or hide the chat bubble. Parameters:visibility:'show'or'hide'
void
app/javascript/entrypoints/sdk.js:87-102
popoutChatWindow()
Open chat in a new popup window. Parameters: None Returns:void
Requirements: showPopoutButton: true must be set
app/javascript/entrypoints/sdk.js:104-110
reset()
Reset the widget and clear all user data. Parameters: None Returns:void
Effects:
- Closes the widget if open
- Clears conversation cookie
- Clears user cookie
- Reloads the widget iframe
- Sets
resetTriggeredflag
app/javascript/entrypoints/sdk.js:195-210
User Management Methods
setUser(identifier, user)
Identify and set properties for the current user. Parameters:identifier(required): Unique user ID (string or number)user(required): User object with at least one property
name: User’s display nameemail: User’s email addressavatar_url: URL to user’s avatar imagephone_number: User’s phone number
void
Throws:
Errorif identifier is not string or numberErrorif user object doesn’t have required keys
app/javascript/entrypoints/sdk.js:112-137
setCustomAttributes(customAttributes)
Set custom attributes for the contact. Parameters:customAttributes(required): Object with custom attribute key-value pairs
void
Throws:
Errorif object is empty or null
app/javascript/entrypoints/sdk.js:139-145
deleteCustomAttribute(customAttribute)
Delete a specific custom attribute from the contact. Parameters:customAttribute(required): Attribute key to delete (string)
void
Throws:
Errorif customAttribute is empty or null
app/javascript/entrypoints/sdk.js:147-154
Conversation Management Methods
setConversationCustomAttributes(customAttributes)
Set custom attributes for the current conversation. Parameters:customAttributes(required): Object with custom attribute key-value pairs
void
Throws:
Errorif object is empty or null
app/javascript/entrypoints/sdk.js:157-165
deleteConversationCustomAttribute(customAttribute)
Delete a specific custom attribute from the conversation. Parameters:customAttribute(required): Attribute key to delete (string)
void
Throws:
Errorif customAttribute is empty or null
app/javascript/entrypoints/sdk.js:167-174
setLabel(label)
Add a label to the current conversation. Parameters:label(required): Label name (string)
void
app/javascript/entrypoints/sdk.js:177-179
removeLabel(label)
Remove a label from the current conversation. Parameters:label(required): Label name (string)
void
app/javascript/entrypoints/sdk.js:181-183
Appearance Methods
setLocale(locale)
Change the widget language. Parameters:locale(optional): Language code (ISO 639-1), defaults to'en'
void
Supported locales:
ar, az, bg, bn, ca, cs, da, de, el, en, es, et, fa, fi, fr, he, hi, hu, id, it, ja, ko, lt, lv, ml, nl, no, pl, pt, pt_BR, ro, ru, sk, sl, sr, sv, ta, th, tr, uk, vi, zh_CN, zh_TW
app/javascript/entrypoints/sdk.js:185-187
setColorScheme(darkMode)
Change the widget color scheme. Parameters:darkMode(optional):'light','dark', or'auto', defaults to'light'
void
app/javascript/entrypoints/sdk.js:189-193
Widget State Properties
hasLoaded
Indicates whether the widget has finished loading. Type:boolean
Read-only
app/javascript/sdk/IFrameHelper.js:158
isOpen
Indicates whether the widget is currently open. Type:boolean
Read-only
app/javascript/entrypoints/sdk.js:63
resetTriggered
Indicates whether the reset() method has been called. Type:boolean
Read-only
app/javascript/entrypoints/sdk.js:73
Events API
Event Listener Pattern
All widget events are dispatched as CustomEvents on the window object.Available Events
chatwoot:ready
Fired when the widget has finished loading and is ready for interaction. Event detail: Noneapp/javascript/widget/constants/sdkEvents.js (CHATWOOT_READY)
chatwoot:opened
Fired when the widget is opened. Event detail: Noneapp/javascript/widget/constants/sdkEvents.js (CHATWOOT_OPENED)
chatwoot:closed
Fired when the widget is closed. Event detail: Noneapp/javascript/widget/constants/sdkEvents.js (CHATWOOT_CLOSED)
chatwoot:on-message
Fired when a new message is received. Event detail: Message objectapp/javascript/widget/constants/sdkEvents.js (CHATWOOT_ON_MESSAGE)
chatwoot:on-start-conversation
Fired when a user starts a new conversation. Event detail: Noneapp/javascript/widget/constants/sdkEvents.js (CHATWOOT_ON_START_CONVERSATION)
chatwoot:error
Fired when an error occurs in the widget. Event detail: Error object with error type and dataapp/javascript/widget/constants/sdkEvents.js (CHATWOOT_ERROR)
chatwoot:postback
Fired when a postback action is received (from interactive messages). Event detail: Postback data objectapp/javascript/widget/constants/sdkEvents.js (CHATWOOT_POSTBACK)
CSS Customization
Widget Container Classes
The widget uses the following CSS classes that you can target for customization:app/javascript/sdk/sdk.js:1-295
Position Classes
Flat Style Widget
The flat style removes rounded corners and shadows:app/javascript/sdk/sdk.js:18-22, 57-62
Custom Widget Color
The widget color is set via the inbox channel configuration and cannot be overridden with CSS. It must be configured in the Chatwoot dashboard.IFrame Communication
The widget usespostMessage for communication between the parent page and the widget iframe.
Message Format
app/javascript/sdk/IFrameHelper.js:94-99
Internal Events
These events are used internally for iframe communication:loaded- Widget iframe has loadedconfig-set- Configuration sent to widgetset-user- User data sent to widgetset-custom-attributes- Custom attributes sentset-conversation-custom-attributes- Conversation attributes sentset-label- Label addedremove-label- Label removedset-locale- Locale changedset-color-scheme- Color scheme changedtoggle-open- Widget open state changedchange-url- Page URL changed
app/javascript/sdk/IFrameHelper.js:155-294
Cookie Management
The widget uses cookies for session persistence:Cookies Used
| Cookie Name | Purpose | Duration |
|---|---|---|
cw_conversation | Stores conversation token | Session |
cw_user_{websiteToken} | Stores user identification hash | Persistent |
cw_snooze_campaigns_till | Campaign snooze timestamp | 1 hour |
app/javascript/sdk/IFrameHelper.js:40-50
Cross-domain Cookies
SetbaseDomain to share conversations across subdomains:
Performance Considerations
Lazy Loading
The widget script supports deferred and async loading:Widget Size
Desktop:- Width: 400px
- Max height: 640px (90% viewport height - 84px)
- Min height: 250px
- Full screen (100% width and height)
app/javascript/sdk/sdk.js:242-289
Browser Support
The widget requires:- ES6 JavaScript support
- postMessage API
- CSS Custom Properties
- Iframe with
allowattribute support
Required Iframe Permissions
The widget iframe requests the following permissions:app/javascript/sdk/IFrameHelper.js:70-71
Security
HMAC Identity Verification
For secure user identification, Chatwoot supports HMAC verification. Contact your Chatwoot administrator to enable this feature.Content Security Policy
If you use CSP, you need to allow:TypeScript Definitions
Related Resources
- Widget SDK Methods - Getting started guide
- Custom Attributes - Custom attribute documentation
- Webhooks - Server-side event handling

