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

# Iframe Persistence

> Persist embedded BoostGPT chat sessions with postMessage

When you embed a BoostGPT AI teammate directly in an iframe, the chat is saved by BoostGPT after the first message is sent. To resume that same chat after your page reloads, store the active `chat_id` sent by the iframe.

## Embed URL

Start with your public page URL and add `embed=1`.

```html theme={null}
<iframe
  id="boostgpt-agent"
  src="https://agent.your-domain.com?embed=1"
  style="width: 100%; height: 720px; border: 0;"
  allow="clipboard-read; clipboard-write; microphone; camera; fullscreen"
></iframe>
```

After the first message, the embedded AI teammate navigates to:

```txt theme={null}
https://agent.your-domain.com/<chat_id>?embed=1
```

## Listen For Chat IDs

BoostGPT sends a `postMessage` event whenever an embedded chat id becomes active.

```js theme={null}
window.addEventListener('message', (event) => {
  if (event.origin !== 'https://agent.your-domain.com') return;
  if (event.data?.type !== 'boostgpt:chat_id') return;

  localStorage.setItem('boostgpt_chat_id', event.data.chat_id);
});
```

Event payload:

```js theme={null}
{
  type: 'boostgpt:chat_id',
  chat_id: 'CHAT_UUID',
  bot_id: 'BOT_UUID',
  embed: true,
  widget: false
}
```

## Restore The Chat

When your page loads again, read the saved chat id and include it in the iframe URL.

```js theme={null}
const iframe = document.getElementById('boostgpt-agent');
const chatId = localStorage.getItem('boostgpt_chat_id');
const baseUrl = 'https://agent.your-domain.com';

iframe.src = chatId
  ? `${baseUrl}/${encodeURIComponent(chatId)}?embed=1`
  : `${baseUrl}?embed=1`;
```

## Full Example

```html theme={null}
<iframe
  id="boostgpt-agent"
  style="width: 100%; height: 720px; border: 0;"
  allow="clipboard-read; clipboard-write; microphone; camera; fullscreen"
></iframe>

<script>
  const baseUrl = 'https://agent.your-domain.com';
  const storageKey = 'boostgpt_chat_id';
  const iframe = document.getElementById('boostgpt-agent');

  const chatId = localStorage.getItem(storageKey);
  iframe.src = chatId
    ? `${baseUrl}/${encodeURIComponent(chatId)}?embed=1`
    : `${baseUrl}?embed=1`;

  window.addEventListener('message', (event) => {
    if (event.origin !== baseUrl) return;
    if (event.data?.type !== 'boostgpt:chat_id') return;

    localStorage.setItem(storageKey, event.data.chat_id);
  });
</script>
```

Use a scoped storage key if you embed multiple AI teammates:

```js theme={null}
const storageKey = `boostgpt_chat_id:${botId}`;
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.