|
| 1 | +--- |
| 2 | +pcx_content_type: how-to |
| 3 | +title: Live View |
| 4 | +description: View and interact with remote Browser Run sessions in real time using the hosted DevTools UI or native Chrome DevTools. |
| 5 | +sidebar: |
| 6 | + order: 2 |
| 7 | + badge: Beta |
| 8 | +--- |
| 9 | + |
| 10 | +import { CURL, DashButton, Tabs, TabItem } from "~/components"; |
| 11 | + |
| 12 | +Live View lets you see and interact with a remote Browser Run session in real time. This is useful for debugging automation scripts, monitoring what a browser is doing, or manually stepping in when a task requires human intervention (see [Human in the Loop](/browser-rendering/features/human-in-the-loop/)). |
| 13 | + |
| 14 | +Live View is available for any browser session created through the [CDP](/browser-rendering/cdp/) endpoints. |
| 15 | + |
| 16 | +## How to access Live View |
| 17 | + |
| 18 | +There are three ways to access Live View: through the Cloudflare dashboard, via the hosted UI at `live.browser.run`, or using native Chrome DevTools. |
| 19 | + |
| 20 | +### Cloudflare dashboard |
| 21 | + |
| 22 | +In the Cloudflare dashboard, go to the **Browser Run** page and select the **Live Sessions** tab. This shows all active browser sessions in your account. Expand a session to see its tabs, then select **Open** to open the Live View for that tab. |
| 23 | + |
| 24 | +<DashButton url="/?to=/:account/workers/browser-rendering" /> |
| 25 | + |
| 26 | +### Hosted UI (any browser) |
| 27 | + |
| 28 | +When you create a session or list targets through the [CDP](/browser-rendering/cdp/) endpoints, the API response includes a `devtoolsFrontendUrl` for each target (tab). Open this URL in any browser to load the DevTools UI hosted at `live.browser.run`, which streams the remote session to your browser. |
| 29 | + |
| 30 | +The hosted UI supports three viewing modes, controlled by the `mode` parameter in the URL: |
| 31 | + |
| 32 | +| Mode | URL pattern | Description | |
| 33 | +| --- | --- | --- | |
| 34 | +| Tab | `https://live.browser.run/ui/view?mode=tab&wss=...` | DevTools inspector panel (Elements, Console, Network, etc.) | |
| 35 | +| Full | `https://live.browser.run/ui/view?mode=full&wss=...` | Full browser chrome with address bar and tab strip | |
| 36 | +| Inspector | `https://live.browser.run/ui/inspector?wss=...` | Standalone inspector view | |
| 37 | + |
| 38 | +### Native Chrome DevTools (Chrome only) |
| 39 | + |
| 40 | +Because Browser Run speaks standard CDP, you can connect Chrome's built-in DevTools directly to a remote session. Replace the `https://live.browser.run/ui/inspector?wss=` prefix in the `devtoolsFrontendUrl` with the `devtools://` protocol: |
| 41 | + |
| 42 | +``` |
| 43 | +devtools://devtools/bundled/inspector.html?wss=live.browser.run/api/devtools/browser/SESSION_ID/page/TARGET_ID?jwt=... |
| 44 | +``` |
| 45 | + |
| 46 | +Paste this URL into Chrome's address bar to open native DevTools connected to the remote browser session. |
| 47 | + |
| 48 | +**Pros:** |
| 49 | +- Familiar UI: the exact same DevTools you use daily for local development, rather than a hosted version wrapped inside a webpage |
| 50 | +- Slightly faster to load: DevTools assets (HTML, JS, CSS) are already bundled locally in Chrome |
| 51 | + |
| 52 | +**Cons:** |
| 53 | +- Chrome only: the `devtools://` protocol URL only works in Chrome. The hosted `live.browser.run` version works in other browsers, though the DevTools UI has not been heavily tested outside Chrome. |
| 54 | +- Inspector tab only: does not work for the full or tab viewing modes |
| 55 | + |
| 56 | +:::caution[URL validity] |
| 57 | +The `devtoolsFrontendUrl` is valid for five minutes from when it was generated. If you do not open the URL within this timeframe, list the targets again to get a fresh URL. Once the DevTools connection is established, it remains active as long as the browser session is alive. |
| 58 | +::: |
| 59 | + |
| 60 | +## View a new session |
| 61 | + |
| 62 | +1. Create a browser session with `targets=true` to include target URLs in the response: |
| 63 | + |
| 64 | +<CURL |
| 65 | + url="https://api.cloudflare.com/client/v4/accounts/ACCOUNT_ID/browser-rendering/devtools/browser" |
| 66 | + method="POST" |
| 67 | + headers={{ |
| 68 | + Authorization: "Bearer {api_token}", |
| 69 | + }} |
| 70 | + query={{ |
| 71 | + keep_alive: "600000", |
| 72 | + targets: "true", |
| 73 | + }} |
| 74 | +/> |
| 75 | + |
| 76 | +```json |
| 77 | +{ |
| 78 | + "sessionId": "1909cef7-23e8-4394-bc31-27404bf4348f", |
| 79 | + "targets": [ |
| 80 | + { |
| 81 | + "description": "", |
| 82 | + "devtoolsFrontendUrl": "https://live.browser.run/ui/inspector?wss=live.browser.run/api/devtools/browser/1909cef7-.../page/8E598E99...?jwt=...", |
| 83 | + "id": "8E598E996530FB09E46A22B8B7754F7F", |
| 84 | + "title": "about:blank", |
| 85 | + "type": "page", |
| 86 | + "url": "about:blank", |
| 87 | + "webSocketDebuggerUrl": "wss://live.browser.run/api/devtools/browser/1909cef7-.../page/8E598E99...?jwt=..." |
| 88 | + } |
| 89 | + ], |
| 90 | + "webSocketDebuggerUrl": "wss://api.cloudflare.com/client/v4/accounts/{account_id}/browser-rendering/devtools/browser/1909cef7-..." |
| 91 | +} |
| 92 | +``` |
| 93 | + |
| 94 | +2. Copy the `devtoolsFrontendUrl` from `targets[0]` and open it in your browser. You now have a live, interactive view of the remote browser session. |
| 95 | + |
| 96 | +## View an existing session |
| 97 | + |
| 98 | +If you have a running session and want to connect to it: |
| 99 | + |
| 100 | +1. List your active sessions: |
| 101 | + |
| 102 | +<CURL |
| 103 | + url="https://api.cloudflare.com/client/v4/accounts/ACCOUNT_ID/browser-rendering/devtools/session" |
| 104 | + method="GET" |
| 105 | + headers={{ |
| 106 | + Authorization: "Bearer {api_token}", |
| 107 | + }} |
| 108 | +/> |
| 109 | + |
| 110 | +2. Using the session ID, list the targets in that session: |
| 111 | + |
| 112 | +<CURL |
| 113 | + url="https://api.cloudflare.com/client/v4/accounts/ACCOUNT_ID/browser-rendering/devtools/browser/SESSION_ID/json/list" |
| 114 | + method="GET" |
| 115 | + headers={{ |
| 116 | + Authorization: "Bearer {api_token}", |
| 117 | + }} |
| 118 | +/> |
| 119 | + |
| 120 | +```json |
| 121 | +[ |
| 122 | + { |
| 123 | + "id": "110850A800BDB8B593CDDA30676635CF", |
| 124 | + "type": "page", |
| 125 | + "url": "https://example.com", |
| 126 | + "title": "Example Domain", |
| 127 | + "description": "", |
| 128 | + "devtoolsFrontendUrl": "https://live.browser.run/ui/view?wss=live.browser.run/api/devtools/browser/28d75446-.../page/110850A8...?jwt=...", |
| 129 | + "webSocketDebuggerUrl": "wss://live.browser.run/api/devtools/browser/28d75446-.../page/110850A8...?jwt=..." |
| 130 | + } |
| 131 | +] |
| 132 | +``` |
| 133 | + |
| 134 | +3. Copy the `devtoolsFrontendUrl` and open it in your browser. |
| 135 | + |
| 136 | +## Get the Live View URL programmatically |
| 137 | + |
| 138 | +You can retrieve the Live View URL from within a Puppeteer or Playwright script using a CDP command. This is useful when you need to share the URL with someone, for example sending it via email, Slack, or displaying it in a UI. |
| 139 | + |
| 140 | +<Tabs> <TabItem label="Puppeteer"> |
| 141 | + |
| 142 | +```js |
| 143 | +const cdp = await page.createCDPSession(); |
| 144 | +const { devtoolsFrontendUrl } = await cdp.send("Cloudflare.getLiveView"); |
| 145 | + |
| 146 | +console.log(`Live View: ${devtoolsFrontendUrl}`); |
| 147 | +``` |
| 148 | + |
| 149 | +</TabItem> <TabItem label="Playwright"> |
| 150 | + |
| 151 | +```js |
| 152 | +const cdp = await page.context().newCDPSession(page); |
| 153 | +const { devtoolsFrontendUrl } = await cdp.send("Cloudflare.getLiveView"); |
| 154 | + |
| 155 | +console.log(`Live View: ${devtoolsFrontendUrl}`); |
| 156 | +``` |
| 157 | + |
| 158 | +</TabItem> </Tabs> |
| 159 | + |
| 160 | +You can also get the Live View URL from the HTTP API by listing targets for a session, as shown in [View an existing session](#view-an-existing-session). Each target in the response includes a `devtoolsFrontendUrl`. |
0 commit comments