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

# Embed the live view

> Show one browser's live view inside your own app, view only or interactive, with a short-lived token and a list of your sites that may frame it.

Your support page, or your end user's own page in your app, can show a browser's live view in an iframe. Your backend mints an embed for one browser over [`/v1`](https://docs.hotkey.so/api#embeds), and the iframe opens its `url`. Nothing else of Hotkey's can be framed by another site: the console and hand links keep `frame-ancestors 'self'`.

## 1. List the sites that may frame your browsers

```bash theme={null}
curl -X PATCH https://console.hotkey.so/v1/workspace \
  -H "Authorization: Bearer $HOTKEY_KEY" -H "content-type: application/json" \
  -d '{ "embed_origins": ["https://app.acme.com", "https://support.acme.com"] }'
```

* Each entry is an origin: `https://`, a host and maybe a port, nothing after it. No wildcards. `http://` on `localhost`, `127.0.0.1` and `.localhost` names only on a hub that itself runs on one (yours, while you develop). At most 10.
* In a team, only owners and admins change the list.
* Taking an origin off the list ends every embed that could only be framed from it, and closes its open views.

## 2. Mint an embed for one browser

```bash theme={null}
curl https://console.hotkey.so/v1/browsers/brw_k3m9x2p7qa4t/embed \
  -H "Authorization: Bearer $HOTKEY_KEY" -H "content-type: application/json" \
  -d '{ "mode": "view", "origins": ["https://support.acme.com"], "expires_in": 900 }'
```

```json theme={null}
{ "id": "emb_4gT9qLx2Wm8ZpA", "object": "embed", "browser": "brw_k3m9x2p7qa4t", "mode": "view",
  "origins": ["https://support.acme.com"], "sites": [], "created": "…", "expires": "…", "revoked": null,
  "status": "live", "ended_why": null,
  "token": "hke_…", "url": "https://console.hotkey.so/hke_…/" }
```

* `mode` is `view` (the default) or `interact`. A view shows the page live and takes no input: clicks, keys, the address and pastes are dropped by the server, whatever the page sends. Interactive takes the input a hand link's guest may give (the mouse, the keyboard, files from the device), in any of the browser's tabs, and its person can answer the browser's asks with Done or Can't do it.
* `origins` defaults to the whole list from step 1; each must be on it (400 `origin_not_allowed`).
* `sites`, up to three, keeps the embed to tabs on those sites and the asks of those tabs. An interactive one can't leave them: a link to another site is refused, as on a hand link, and a page that leaves them anyway ends the view. A view locks nothing: when its tab goes to another site (your agent navigates), its picture stops until the tab is back, and your page hears `away` and `back`.
* A mint isn't kept under an `Idempotency-Key` (its answer holds the token): each call mints a new embed.
* `expires_in` is 30 to 86400 seconds, 900 by default. The embed opens until then, and a view still open at that moment ends too.
* `token` and `url` come in this answer only. Mint one per page load, on your server, and put the `url` straight into the iframe. Don't log it or send it to anyone else: whoever has it sees, or drives, that browser until it ends.
* A browser has at most 50 live embeds (409 `embed_limit`).

`GET /v1/browsers/{id}/embeds` lists a browser's embeds, `GET /v1/embeds/{id}` reads one, and `DELETE /v1/embeds/{id}` revokes it: its open view ends at once. An embed also ends when its browser is deleted or moved to another workspace.

## 3. Frame it

```html theme={null}
<iframe id="hotkey" src="https://console.hotkey.so/hke_…/" style="width:100%;height:640px;border:0"></iframe>
```

The page answers with `Content-Security-Policy: frame-ancestors` set to the embed's origins, so a page of any other site gets a refused frame. It asks for no camera, microphone or location, and sends no Referer.

What the embed never shows: the browser's clipboard, its saved sign-ins and passkeys, its downloads, the address bar, and the links of its asks.

One person watches a browser at a time. An embed that opens takes the browser from another embed, which then says it is open elsewhere. It never takes it from someone signed in (your staff in the console) or from someone doing an ask through a hand link: it waits, says so, and tries again every 5 seconds. A view never gets the live page mode, which sends the page's DOM.

## 4. Hear what happens

The frame posts `{ hotkey: { type, … } }` messages to your page:

```js theme={null}
const hotkey = document.getElementById('hotkey');
addEventListener('message', (e) => {
  if (e.origin !== 'https://console.hotkey.so' || e.source !== hotkey.contentWindow) return;
  const m = e.data?.hotkey;
  if (m?.type === 'ended') mintAnotherOrHide(m.reason);
});
```

| `type` | When | Fields |
| - | - | - |
| `ready` | The view is connected | `browser`, `mode`, `tab`, `tabs`, `expires` (ms since 1970) |
| `live` | The first picture of a tab shows | `tab` |
| `tabs` | The browser's tabs changed | `tabs` |
| `tab` | The tab shown changed | `tab` |
| `ask` | An ask was raised in the browser | `ask`: `id`, `reason`, `tab` |
| `ask-ended` | That ask was answered, cancelled or ran out | `id` |
| `busy` | Someone has the browser; the view waits | `reason`: `link` (an ask through a hand link) or `person` (someone signed in) |
| `away`, `back` | A view's tab left its `sites`, or came back | |
| `replaced` | The browser was opened somewhere else | |
| `ended` | The embed ended | `reason`: `revoked`, `expired`, `origins-removed`, `browser-deleted`, `browser-moved`, `off-site` |

A tab is `{ id, title, url }`. The `id` is the live view's own, not an agent's tab number.

Your page may send two messages to the frame, with `hotkey.contentWindow.postMessage({ hotkey: … }, 'https://console.hotkey.so')`:

* `{ type: 'switch', tab: '<id>' }` shows that tab (one of `tabs`, and on the embed's `sites` when it has some).
* `{ type: 'state' }` answers with `ready` again, for a page that started listening late.

The frame takes them only from its parent, and only from one of the embed's origins.

## Security

* The token is the credential. Treat it like a short-lived session: mint it per view, keep `expires_in` short, and revoke it when your page closes the view.
* `frame-ancestors` stops another site from framing the view. It doesn't stop someone who has the token from opening it in a tab of their own, which is why the token is short-lived and only in your page.
* Asks raised while an embed watches show in it without their link. To give someone a step, send the ask's link yourself (`POST /v1/asks`).


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