> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bkstr.io/llms.txt
> Use this file to discover all available pages before exploring further.

# JavaScript API

> Control the Bookster chat widget programmatically from your website

The widget exposes a global `window.Bookster` object that you can use to control it from your own JavaScript.

## Open the widget

```javascript theme={null}
// Open the chat widget
window.Bookster.open();

// Open with a pre-filled message
window.Bookster.open({
  message: "I'd like to book a haircut for tomorrow"
});
```

## Examples

### Custom button

```html theme={null}
<button onclick="window.Bookster.open()">
  Chat with us
</button>
```

### Open with context from another page element

```html theme={null}
<div class="service-card">
  <h3>Deep Tissue Massage</h3>
  <p>60 minutes — $120</p>
  <button onclick="window.Bookster.open({message: 'I want to book a Deep Tissue Massage'})">
    Book now
  </button>
</div>
```

### Wait for widget to be ready

The widget fires a `bookster-widget-ready` event on the window when it has finished loading:

```javascript theme={null}
window.addEventListener("message", (event) => {
  if (event.data.type === "bookster-widget-ready") {
    console.log("Bookster widget is ready");
  }
});
```

<Info>
  The `window.Bookster` object is only available after the widget script has loaded. If you need to call it immediately, use the `bookster-widget-ready` event to know when it's safe.
</Info>
