# JavaScript API

> Open and close Messenger from code, and prefill the visitor's name and email.

## `CustomerCatalystMessenger`

Set by `messenger.js` as soon as it runs.

| Call | Does |
|---|---|
| `CustomerCatalystMessenger.open()` | Opens Messenger on its home screen. |
| `CustomerCatalystMessenger.open('new')` | Opens the new-message screen. |
| `CustomerCatalystMessenger.close()` | Closes Messenger and puts focus back where it was. |

```js
document.querySelector('#help-link').addEventListener('click', function (e) {
  e.preventDefault();
  CustomerCatalystMessenger.open('new');
});
```

If you call `open()` before Messenger has loaded its settings, it opens as soon as they arrive. When Messenger is off, or the page's site isn't on the key's list, `open()` does nothing.

For buttons, the [`data-ccm-open` attribute](/support/messenger/open-from-your-button/) needs no JavaScript.

## `window.ccMessengerSettings`

Optional. Set it **before** the Messenger script tag.

```html
<script>
  window.ccMessengerSettings = {
    name: 'Maria Lund',
    email: 'maria@example.com'
  };
</script>
<script src="https://widget.customercatalyst.io/v1/messenger.js" data-key="pk_…" async></script>
```

| Key | Value |
|---|---|
| `name` | Prefills the name on the new-message screen. |
| `email` | Prefills the email on the new-message screen. |
| `key` | Your public key, used when the script tag has no `data-key`. |

Name and email only **prefill** the fields; the visitor can change them, and they don't sign the visitor in. Once a browser has sent a message, Messenger uses the name and email it remembered instead.

:::note[Coming later]
Recognising signed-in users (so they see their conversations on every device) is planned.
:::

## `CustomerCatalystForm`

`form.js` sets `window.CustomerCatalystForm` to mark that it loaded. It has no methods; open the form with [`data-open`](/developers/embed-reference/#support-form--v1formjs).
