Widget

A chat button and panel you add to any website with one script tag. It runs in an iframe, so it never touches your page’s styles or scripts.

Starting a new integration?

The SDK streams answers, formats them as markdown, and adds callbacks, a React component and a headless client. This widget keeps working for existing sites.

Set this up with your AI agent

Set up the Docket website widget in this project.

Docket answers questions from my own documents and checks every answer against them. It is hosted at https://YOUR_HOST. Docs: https://YOUR_HOST/docs?page=widget

My publishable key: pk_live_PASTE_YOUR_KEY_HERE
If that still says PASTE, ask me for the key. Never invent one.

What to do
1. Look at the project first: the framework, where the shared layout or index.html lives, and how scripts are loaded. If something important is unclear, ask me one short question before you change anything.
2. Add the widget script once, site-wide, before the closing </body> tag:
   <script src="https://YOUR_HOST/widget.js" data-key="MY_PUBLISHABLE_KEY"></script>
   In React or Next.js, load it once from an effect in a client component and clean up when it unmounts:
   const script = document.createElement("script");
   script.src = "https://YOUR_HOST/widget.js";
   script.dataset.key = "MY_PUBLISHABLE_KEY";
   document.body.appendChild(script);
   return () => { window.DocketWidget?.destroy(); script.remove(); };
3. Set only the options I ask for. Available data- attributes: data-theme (light, dark or auto), data-position (bottom-right or bottom-left), data-accent-color (a hex color), data-open (true), data-title (label for the chat button).
4. Check it works: start the dev server, load a page, and confirm a chat button appears and the browser console shows no Docket errors.

The key
- It must be a publishable key. It starts with pk_live_ and is safe to put in a web page. I create it in Studio: open the group, go to Keys, choose Publishable.
- Never use a key that starts with sk_ in the browser.

If the widget does not load
- "Missing data-key": the key is empty.
- "Origin is not authorized": add this site's address to the group's allowed domains in Studio.
- 404 from /api/widget-config: the script was loaded from a different server than the Docket app. Load it from https://YOUR_HOST.

When you finish, list the files you changed. Do not change anything unrelated.

Install

Add the script before the closing </body> tag. The key must be a publishable key (pk_live_…).

index.html
<script
src="https://YOUR_HOST/widget.js"
data-key="pk_live_YOUR_PUBLIC_KEY"
></script>

Options

Set options as data- attributes on the script tag. Color and position default to the values in your group’s settings, so you only set them to override.

AttributeValuesDescription
data-keypk_live_…Required. Your publishable key.
data-accent-colorHex colorColor of the chat button.
data-positionbottom-right, bottom-leftCorner of the page.
data-themelight, dark, autoDefaults to auto, which follows the visitor’s system.
data-opentrueOpen the chat as soon as the page loads.
data-titleTextLabel for the chat button, used by screen readers. Defaults to “Open chat”.
data-hostURLOrigin of your Docket app. Only needed when widget.js is served from somewhere else.

JavaScript API

The script adds window.DocketWidget so your own buttons can control the chat.

MethodDescription
open()Open the chat panel.
close()Close it.
toggle()Open it if closed, close it if open.
clear()Clear the conversation.
destroy()Remove the widget from the page.
<button onclick="DocketWidget.open()">Ask our docs</button>

React and Next.js

Load the script once from an effect, and remove the widget when the component unmounts.

DocketWidget.tsx
"use client";
import { useEffect } from "react";
export function DocketWidget() {
useEffect(() => {
const script = document.createElement("script");
script.src = "https://YOUR_HOST/widget.js";
script.dataset.key = "pk_live_YOUR_PUBLIC_KEY";
document.body.appendChild(script);
return () => {
(window as any).DocketWidget?.destroy();
script.remove();
};
}, []);
return null;
}

Troubleshooting

Open the browser console. The widget logs the reason when it cannot start.

  • Missing data-key: the script tag has no key, or it is empty.
  • Secret keys must never be used in the browser: you passed an sk_ key. Use a publishable pk_ key instead.
  • Origin is not authorized: the key only allows certain sites and yours is not one of them. See API keys.
  • 404 from /api/widget-config: the script was loaded from a different server than your Docket app. Load it from the app, or set data-host.