Embed a live phone in your app
Show your own users a live Android phone inside your web app, for example a preview of the app your product just built. They watch it, or tap, swipe and type on it, without a Mobilebox account. You get a short-lived iframe URL, signed by us and bound to one phone and one page origin.
1. Allow your origins once
Tell Mobilebox which pages may hold the iframe. Up to 20 origins: https://host[:port], https://*.example.com for any subdomain, or http://localhost:port while you develop.
curl -X PUT https://mobilebox.dev/v1/embed/origins \
-H "Authorization: Bearer $MOBILESANDBOX_API_KEY" -H "Content-Type: application/json" \
-d '{"origins": ["https://app.example.com", "https://*.preview.example.com"]}'2. A phone with a smooth screen
Create the phone with display_hz: 30: its display runs at 30 Hz instead of 15, so scrolling and animations look smooth in the preview.
curl -X POST https://mobilebox.dev/v1/phones \
-H "Authorization: Bearer $MOBILESANDBOX_API_KEY" -H "Content-Type: application/json" \
-d '{"display_hz": 30}'30 Hz costs more of the server while the screen moves, so a server runs a few such phones at once. Past that the phone runs at 15 Hz and the answer has a notice; it is never refused, and its next start gets 30 Hz when there is room. The phone JSON’s display_hz says what it runs at now.
3. Make a link for a running phone
curl -X POST https://mobilebox.dev/v1/phones/$PHONE_ID/embed \
-H "Authorization: Bearer $MOBILESANDBOX_API_KEY" -H "Content-Type: application/json" \
-d '{"origin": "https://app.example.com", "interactive": true, "ttl": 900}'The answer has url, expires_at, origin, interactive and snippet:
{
"url": "https://mobilebox.dev/embed?t=e1.ph_…",
"expires_at": "2026-11-25T10:15:00.000Z",
"origin": "https://app.example.com",
"interactive": true,
"snippet": "<iframe src=\"https://mobilebox.dev/embed?t=e1.ph_…\" width=\"360\" height=\"800\" style=\"border:0\" title=\"Phone preview\"></iframe>"
}originis the page that holds the iframe, and must be on your list.interactivedefaults tofalse(view-only). Withtrue, your user’s taps, swipes and typing reach the phone, plus the back, home, enter, delete, recents and tab keys. Never power.ttlis how long the link opens: 60 to 3600 seconds, 900 by default.
Make the link on your server, where your API key lives, and hand only the URL to the browser.
4. Put it in your page
<iframe src="https://mobilebox.dev/embed?t=e1.ph_…" width="360" height="800" style="border:0" title="Phone preview"></iframe>The phone’s screen fills the frame at its own aspect ratio. Size the iframe as you like; 360×800 fits a 1080×2400 phone.
When it ends
The link opens until expires_at. Make a new one before then and swap the iframe’s src. An open embed ends:
- at
expires_at; - when the phone parks, stops or is deleted;
- on
DELETE /v1/phones/{id}/embed, which ends every embed link of that phone at once, open ones included. Do this when your user leaves the preview.
The embed tells its parent page, and only the origin it was made for:
window.addEventListener('message', (e) => {
if (e.origin !== 'https://mobilebox.dev') return // with several embeds, e.source says which iframe
const m = e.data
if (m?.type === 'mobilebox:live') { /* on screen: m.width × m.height (the phone's pixels), m.interactive */ }
if (m?.type === 'mobilebox:state') { /* m.state: connecting, reconnecting, paused (your own user is typing on it) */ }
if (m?.type === 'mobilebox:end') { /* m.reason: make a new link, or show your own fallback */ }
})End reasons:
| Reason | Meaning |
|---|---|
expired | Past expires_at |
revoked | DELETE /v1/phones/{id}/embed |
parked, failed, deleted | The phone parked, stopped or was deleted |
invalid | Not a link we made, or cut short |
not_framed | Opened as a page of its own |
unreachable | No stream for about a minute; the embed offers Try again |
unsupported | The browser has no WebCodecs (e.g. Safari before 16.4) |
When the embed isn’t live it keeps the last frame, dimmed, under a short line your user can read. If you see the browser’s own "blocked" page icon inside the iframe, the page’s origin is not the link’s origin.
Keyboard and pointer. On an interactive link, your user taps or clicks; a tap shows a ring at once. A click (or Tab to the preview) lets them type. Enter, Backspace and Escape (Back) go to the phone, and the wheel or a trackpad scrolls it. On a touch screen the phone’s own keyboard comes up. A view-only link never blocks the page from scrolling.
What your users get, and what they don’t
- One phone’s screen. No other phone, no account, no API key, no billing, no agent captions, no way into Mobilebox.
- Only your pages can frame it. The browser refuses any other parent: CSP
frame-ancestorsis exactly the link’s origin. The link opened as a page of its own shows nothing. - Short-lived and revocable. A link stops at
expires_at, or onDELETE /v1/phones/{id}/embed. - Your own user wins. While someone signed in to your workspace has taken control of the phone in the live view (to type a password or a code), embeds pause, and their input is refused with
human_in_control.
Treat an embed URL like a short-lived password to that one phone. Whoever holds it can do what the iframe can, until it expires or you revoke it. Keep ttl short for interactive links, and revoke when the session ends.
Billing
An embedded phone is billed as normal phone minutes while it runs. Taps and typing count as activity, so a phone someone plays with doesn’t park while idle; watching alone doesn’t.
MCP
embed_phone {phone_id, origin, interactive?, ttl_seconds?} returns the URL and the snippet. Set the allowed origins with PUT /v1/embed/origins.
Android phones only for now. Errors: errors and recovery (origin_not_allowed, embed_link_expired, embed_view_only, …).
Source: docs/EMBED.md in the repo, rendered at build time.