jackwener/OpenCLI · error
Target tab ${candidate} could not be validated in the curren
Error message
Target tab ${candidate} could not be validated in the current browser session. The Browser Bridge session may have restarted; re-run "opencli browser tab list" and choose a current target. What it means
When resolving an explicitly requested browser tab, the CLI calls page.tabs() to enumerate current targets. If that call itself throws (the bridge connection is dead, e.g. the browser session restarted), the code clears any saved target state is only cleared for saved-source lookups; for explicit candidates it throws an Error telling the user the candidate could not be validated and to re-list tabs, with the original error as cause.
Source
Thrown at src/cli.ts:575
}
async function resolveBrowserTargetInSession(
page: import('./types.js').IPage,
targetPage: string,
opts: { scope: string; source: 'explicit' | 'saved' },
): Promise<string | undefined> {
const candidate = targetPage.trim();
if (!candidate) return undefined;
let tabs: unknown[];
try {
tabs = await page.tabs();
} catch (err) {
if (opts.source === 'saved') {
saveBrowserTargetState(undefined, opts.scope);
return undefined;
}
throw new Error(
`Target tab ${candidate} could not be validated in the current browser session. ` +
'The Browser Bridge session may have restarted; re-run "opencli browser tab list" and choose a current target.',
{ cause: err },
);
}
if (Array.isArray(tabs) && hasBrowserTabTarget(tabs, candidate)) {
return candidate;
}
if (opts.source === 'saved') {
saveBrowserTargetState(undefined, opts.scope);
return undefined;
}
throw new Error(
`Target tab ${candidate} is not part of the current browser session. ` +
'The Browser Bridge session may have restarted; re-run "opencli browser tab list" and choose a current target.',View on GitHub (pinned to 49907e53dc)
Solutions
- Re-run `opencli browser tab list` to see currently valid targets and pick one of those.
- Reopen or reattach the browser session before retrying the command.
- Handle the retry in scripts: catch, re-list, and re-resolve the target instead of caching tab IDs across runs.
- Inspect the `cause` property of the error for the underlying transport failure if the bridge seems up.
Example fix
// before
const tab = savedTabId; // stale across restarts
await run(tab);
// after
const tabs = await listTabs();
const tab = tabs.find(t => t.url.includes('/reports'))?.id ?? tabs[0].id;
await run(tab); Defensive patterns
Strategy: retry
Validate before calling
async function bridgeIsAlive(page) {
try { await page.tabs(); return true; } catch { return false; }
}
if (!(await bridgeIsAlive(page))) throw new Error('Browser Bridge is down; restart the session'); Type guard
function isAliveTabsResult(v: unknown): v is Tab[] {
return Array.isArray(v) && v.every(t => typeof t === 'object' && t !== null && 'id' in t);
} Try / catch
try {
await resolveBrowserTargetInSession(page, candidate, { source: 'explicit' });
} catch (err) {
if (err instanceof Error && err.message.includes('could not be validated')) {
await restartBrowserSession();
const tabs = await listTabs();
candidate = pickTarget(tabs);
return resolveBrowserTargetInSession(page, candidate, { source: 'explicit' });
}
throw err;
} Prevention
- Don't cache tab IDs across script runs; re-resolve each run.
- Run `opencli browser tab list` before long automations to verify the bridge.
- Handle browser restarts/crashes in scripts with a re-list-and-retry step.
- Keep only one automation session driving the shared browser.
When it happens
Trigger: resolveBrowserTargetInSession('explicit') invoked and page.tabs() rejects — the Browser Bridge websocket died, the browser was closed/restarted, or the session name no longer maps to a live page between resolving and validating.
Common situations: Long-lived scripts holding a session while the browser auto-updates or crashes; referencing a saved tab ID in a new terminal after the bridge restarted; running two CLI sessions where one closes the shared browser.
Related errors
- Target tab ${candidate} is not part of the current browser s
- Browser session required for bilibili follow
- Browser session required for bilibili following
- Could not detect a logged-in GitHub account
- Browser session required for gmail attachments
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/46991149f9ab8a3e.
Report an issue: GitHub.