Casdesk
Sites and the widget

The widget

The widget is a small script, about 9 KB gzipped. It draws the chat in a shadow root, so your page's CSS does not change it and its CSS does not change your page. It uses no iframe and no third-party cookies.

Embed code

<script src="https://desk.casdoor.com/widget.js" data-site="example-com" async></script>

Put it into every page, before </body>. On pages without it, the chat does not show, and visits to those pages are not tracked.

AttributeMeaning
data-siteThe site's name (required)
data-langen or zh. By default the site's language setting, or the visitor's browser language
data-launcher="false"Hides the round button. Open the chat from your own button with Casdesk.open()
data-mode="page"Fills the whole page with the chat, instead of a button and a panel

JavaScript API

Once the script has loaded, the page can call:

CallDoes
Casdesk.open()Opens the chat
Casdesk.close()Closes it
Casdesk.toggle()Opens or closes it
Casdesk.setUser({ id, username, name, email, hash })Tells the chat who the signed-in user is, see Signed-in visitors

The widget fires a casdesk:ready event on window when it is ready. For example, a "Chat with us" button of your own:

<script src="https://desk.casdoor.com/widget.js" data-site="example-com" data-launcher="false" async></script>
<button onclick="window.Casdesk && Casdesk.open()">Chat with us</button>

With data-launcher="false", Casdesk.open() goes straight to the conversation, since your own button stands for the widget's home.

The chat page

Each site also has a page of its own, to link to from "Contact us", from emails or from an app:

https://desk.casdoor.com/chat/example-com

It shows the same conversation as the widget on your website, in the same browser.

Content Security Policy

If your website sends a Content-Security-Policy header, allow https://desk.casdoor.com in script-src, connect-src and img-src.

On this page