A browser session lifecycle an agent can reason about
Create, inspect, connect and close Cloudflare Browser Run sessions without confusing access links with persistent browser state.
Use tab identifiers, inspect popups and manage a small tab set without relying on tab order.
Treat tab_id as part of the operation's identity whenever a session contains more than one page. Lupin defaults to the first page if you omit it, which is convenient for a simple one-page task but fragile after a popup, new tab or manual takeover. A tab's title is useful context; it is not a stable identifier. Two tabs can show the same title or URL while holding different form state. Record the returned tab_id together with the page URL and the task step that opened it, then send that identifier on subsequent actions.
The tabs action returns page targets with their identifiers, titles and URLs. Call it after an action that might open another page and after a human changes the session. Choose the target whose current URL and observed role match the intended workflow. Do not infer that the newest array entry is always the sign-in popup or that the first tab is still the original document. The action surface reports at most twenty targets, while its own new-tab creation refuses to exceed ten pages. Keep the working set deliberately smaller than either limit so the task remains understandable.
Use new_tab with an approved public URL when the workflow needs a second source without replacing the first. Save the tab_id returned by that action. Use navigate with the same identifier to replace that tab's document intentionally. A new blank tab is not evidence that the destination was reached; inspect the resulting URL and content after navigation. If a requested tab no longer exists, tab_not_found is a signal to refresh the inventory. Reusing a stale identifier repeatedly will not recreate the old page or recover its transient state.
{"action":"read","tab_id":"TARGET_ID_FROM_TABS"}Close tabs as soon as their evidence has been saved and the task no longer needs their page state. close_tab requires an explicit tab_id, which makes the destructive target clear. A research comparison might retain an index page and one source page, then reuse the source tab for the next approved document. That pattern limits accidental context mixing and makes cleanup easier. Closing one tab does not end the entire browser session, and it does not guarantee that the remaining tab is the same first page your earlier default-target actions selected.
Assign a single controller to each active tab while a human takeover is happening. Pause automation before the operator navigates or enters credentials, then refresh tabs and read the selected page when control returns. A fresh inventory is more reliable than assuming the handoff preserved focus. Keep session-level cleanup separate: after all tab work is complete, end the browser session explicitly. Browser state remains temporary even if a tab identifier was stored in a durable task record. Store the evidence and decision that the tab supported, not an expectation that the target can be reopened after session closure.
Reviewed against the current Lupin route, provider adapter and shared input contracts, plus the linked official references. Examples were not run against live services.
Prepared with AI assistance by Lupin editorial. How we research and maintain these guides.