Skip to main content
Add the CometChat Widget with a single snippet in a Webflow Embed element. Pick the sign-in flow that matches your site: guests, auto-created users from your IDs, or backend-issued auth tokens. Choose how visitors sign in:

Anonymous Chat (Guest Mode)

  • Visitors can chat without accounts.
  • Fastest, friction-free setup.

Create + Log In User On The Fly

  • Auto-create CometChat users with your existing IDs (email, user ID, etc.).
  • No backend needed; CometChat creates users on first visit.

Backend-Created User (Auth Token Login)

  • Use your backend to issue auth tokens.
  • Keep your Auth Key off the page.

Where to place the snippet in Webflow

1

Open Custom Code settings

Log in to Webflow, select your site, then open Site Settings → Custom Code.
2

Load the CometChat script once (recommended)

Add this to Head Code so every Embed can reuse it:
If you prefer, you can keep the script tag directly inside the Embed snippet instead.
3

Save and publish

Click Save, publish the site, then Visit Website to confirm the widget appears.

1. Anonymous Chat (Guest Mode)

Use this when: you want visitors to chat without signing in.

Paste this into the Webflow Embed

Update these values


2. Create + Log In User On The Fly

Use this when: you already have user IDs (email, username, member ID) and want to log people in with that ID automatically. CometChat creates the user the first time it sees the ID.

Add this to Site Settings → Custom Code → Head Code

Paste this into the Webflow Embed

Update these values

Memberstack auto-login (Webflow + Memberstack, still UID flow)

Use this when your Webflow site uses Memberstack and you want the widget to log members in automatically (with a persistent guest fallback). Step 1 — add Memberstack to Head (Site Settings → Custom Code → Head):
Step 2 — add the chat widget (Site Settings → Custom Code → Footer, or a page Embed):
Optional (without reload): listen for Memberstack auth changes and swap users/guests.

3. Backend-Created User (Auth Token Login)

Use this when: people sign in through your backend and you generate their CometChat auth token server-side. This keeps your Auth Key off the page. Server-side flow (auth token login):
  1. Authenticate the user in your app.
  2. If it’s their first time, call Create User (https://www.cometchat.com/docs/rest-api/users/create) — you can also request an auth token in that call.
  3. For returning users, call Create Auth Token (https://www.cometchat.com/docs/rest-api/auth-tokens/create) to issue a fresh token.
  4. Send the token to the browser and place it in the widget config below.
  5. The same token works for the CometChat Widget, UI Kit, or SDK.
Full walkthrough: How to properly log in and create users in CometChat.

Paste this into the Webflow Embed

Update these values


Troubleshooting

  • Widget not appearing? Ensure the Embed is set to Code and the script loads (chat-embed@1.x.x). Publish the site after adding the snippet.
  • Login/auth errors? For UID mode, ensure the uid is unique and you’re using an App Auth Key (not REST API key). For auth token mode, make sure the token matches the logged-in user.
  • Only guests showing? Confirm you’re providing uid or authToken in the snippet and that your page logic passes the right IDs.
  • Embed clipped? Resize the Embed element to give the widget enough space (width/height also configurable in the config).

Advanced JavaScript Controls

The embed works out of the box. Use the helpers below only if you need to open a specific chat, listen for widget events, or change settings on the fly.

Before you follow advanced setup steps

  1. Keep the standard widget snippet (from the Integration guide) on your page.
  2. Add another <script type="module"> right after it or inside your site builder’s “custom code” area.
  3. Wrap your code in window.addEventListener("DOMContentLoaded", () => { ... }) so it runs after the widget loads.
  4. Replace placeholder text such as UID, GUID, and LANGUAGE_CODE with your real values.
When the widget is ready, it exposes a global helper named CometChatApp. Every example below shows a tiny recipe you can paste inside the script mentioned above.

Open a chat or start a call

Use these helpers when you want the widget to jump straight to a person/group or begin a call. Drop the snippet inside your custom script and replace UID/GUID with real IDs from your CometChat app.

Listen for widget events

Run your own code when something happens inside the widget—new message, docked bubble opened, or someone switching chats. Keep the event names as shown; just change what happens inside each arrow function.

Create/Update users on the fly

  • This will only work with authKey
If you collect names, avatars, or profile links on your site, you can push them straight into CometChat. Replace the placeholders and run the snippet after the widget loads.

Create/Update groups on the fly

If you want to create groups directly from your page, use this snippet. Replace the placeholders and run the snippet after the widget loads.

Log users in or out with code

Use an auth token if you have a backend, or fall back to a plain UID for quick tests. Run these helpers after the widget loads.

Control where data is stored

Pick whether the widget should remember login info in the browser tab only (SESSION) or across visits (LOCAL). Update the placeholders, then drop this script right after the default widget embed.

Change the widget language

The widget auto-detects the browser language, but you can force it to any supported locale. Run the helper once after the widget loads and swap in the language code you need.
Popular codes Need another locale? Use the same pattern with its code (for example CometChatApp.localize("ko") for Korean).

Need Help?

If you have questions or run into issues, reach out to CometChat Support.