--- name: browser-workflow description: Use the browser in the background to inspect websites and complete web tasks. Page is the default for reading and interaction; Surface supplements it when visual context or missing page semantics require it. Includes Canvas workflows. --- # Browser Workflow Use the installed browser API through a thin wrapper. **Page is the default for initial inspection and routine interaction.** Surface supplements Page when the task depends on visual layout or Page does not provide enough information to identify or operate the target. Both share the same browser tab, while the user's working window keeps its focus. ## Connect In `mcp__node_repl__js`, initialize once: ```javascript var { connectBrowser } = await import(nodeRepl.homeDir + '/.codex/plugins/browser-workflows/skills/browser-workflow/scripts/connect-browser.mjs'); var connection = await connectBrowser({ sessionName: '🔎 Browser task' }); var browser = connection.browser; ``` Use `browser.user.openTabs()` to choose the actual requested tab. Then claim that observed object and begin with Page: ```javascript var tab = await browser.user.claimTab(observedTab); var session = connection.session(tab); nodeRepl.write(await session.read()); ``` Continue with `session.page` locators grounded in that page state. Reuse these handles throughout the task. An existing browser can be passed as `{ browser, sessionName }`; an explicit tab mention follows the host's exact matching rules. The wrapper initializes the existing bundled browser client inside the trusted Node service and returns `{ agent, browser, session, newTab }`, or the original dependency/access error. Routine work uses this skill and its compact [API reference](references/javascript.md); connection does not fetch or print the full host manual. For an uncovered capability, consult only its relevant API topic as needed. Marketplace discovery is for adding services; this installed entry handles browser connection. ## New task tabs For a signed-in Chrome task with no suitable open page, create a task tab automatically and inspect the destination before asking for login: ```javascript var tab = await connection.newTab(); await tab.goto(requestedURL); var session = connection.session(tab); nodeRepl.write(await session.read()); ``` An absent Canvas tab is not evidence of an expired login. Existing cookies remain available in the new Chrome tab. Ask the user only for the specific authentication step the destination actually requires. The helper checks focus; an unexpected change returns the created `tabId` for diagnosis rather than repeating creation. Creating a task tab needed for the requested work is already within scope; a background tab needs no separate permission question. For a new public page or local preview that does not need the user's Chrome login state, select the hidden in-app browser: ```javascript var preview = await connectBrowser({ browserType: 'iab', sessionName: '🔎 Page preview' }); var tab = await preview.newTab(); await tab.goto(requestedURL); var session = preview.session(tab); nodeRepl.write(await session.read()); ``` `newTab()` wraps the native `browser.tabs.new()`. For the in-app browser it checks that the preview remains hidden; for Chrome it checks focus and active-tab state. It does not show the page or replace a user tab. Chrome and the in-app browser have different account state; an explicit Chrome/account/tab request keeps that backend. For Chrome, `connection.newTab()` uses native `tabs.new()` in the same account context and checks window focus and selected tabs before and after creation. The management capability organizes browser state; it is not the task-tab creation entry. If the in-app browser is already visible, reuse a suitable task tab or discuss the specific visible change. Backend selection is a task-routing decision, not a way to retry a blocked access through another channel. ## Two native interfaces | Layer | Use | API | | --- | --- | --- | | **Page — primary** | Initial page reading, exploration, locating, filling, clicking and file transfer | `session.page` is `tab.playwright` | | **Surface — supplementary** | Resolve a visual requirement or a specific gap in Page's target information or interaction | `session.surface` is `tab.ax` | `session.read()` reads the DOM; `session.screenshot(options)` captures the tab. Surface uses the native host methods and argument shapes. Its availability is explicit (`null` when the host omits it). [API examples](references/javascript.md) cover setup details and both layers. Observe relevant page state, act, and check the result. An exploratory request such as “look at this page” starts with Page too. Choose Surface for a concrete visual requirement or an observed Page limitation; use the resulting evidence to continue with Page where practical. A screenshot request or visual-layout task can go directly to the relevant visual API. Preserve account identity and any action already attempted when changing layers. The host's permissions apply to both. Background work preserves the foreground application, the user's selected tab, and window layout. For an ordinary navigation link, inspect its `href` and `target`, then navigate an already controlled background task tab to the observed URL. A link click can open or select another tab, even without an explicit focus call; treat `_blank`, popups and new-window controls as visibility-sensitive. Use the hidden task-tab entry above for new public/preview work; reserve agreement for an actual foreground or user-tab change. If the only usable tab is the user's active working page, agree on its use before replacing it. Deliver results as links or captured images so the user can inspect them when convenient. A verification screenshot uses background capture; showing or activating a browser/app, selecting the user's tab, and bringing a window forward each require prior agreement. If focus unexpectedly changes, pause UI actions and report the operation; automatically switching it back can interrupt the user's next action too. Public web search is useful for discovery and public facts. A request to inspect a particular website or signed-in page retains that browser step; clearly distinguish search findings from information verified on the actual page. For a failed setup, stale tab, or repeated read timeout, use the focused [recovery reference](references/diagnostics.md). For Canvas, also read [Canvas](../canvas/SKILL.md). Load [file-transfer helpers](references/interface.md) only when useful.