jackwener/OpenCLI · error
browser focus is not supported by this browser backend
Error message
browser focus is not supported by this browser backend
What it means
The `browser focus` command feature-detects `page.focus` on the active backend and throws this error when the method is absent. It signals that the connected browser backend cannot programmatically focus elements.
Source
Thrown at src/cli.ts:2127
if (!resolvedTarget) return;
const parsed = nthToResolveOpts(opts?.nth);
if ('error' in parsed) {
console.log(JSON.stringify({ error: { code: 'usage_error', message: parsed.error } }, null, 2));
process.exitCode = EXIT_CODES.USAGE_ERROR;
return;
}
const { matches_n, match_level } = await page.hover(resolvedTarget, parsed.opts);
console.log(JSON.stringify({ hovered: true, target: resolvedTarget, matches_n, match_level }, null, 2));
}));
addBrowserTabOption(
addSemanticLocatorOptions(browser.command('focus'))
.argument('[target]', 'Numeric ref (from browser state / find), CSS selector, or omit when using --role/--name/etc.')
.option('--nth <n>', 'When <target> is a multi-match CSS selector, pick the nth match (0-based)')
.description('Focus an element — JSON envelope {focused, target, matches_n}'),
)
.action(browserAction(async (page, target, opts) => {
if (typeof page.focus !== 'function') throw new Error('browser focus is not supported by this browser backend');
const resolvedTarget = await resolveWriteTargetOrPrint(page, target, opts ?? {});
if (!resolvedTarget) return;
const parsed = nthToResolveOpts(opts?.nth);
if ('error' in parsed) {
console.log(JSON.stringify({ error: { code: 'usage_error', message: parsed.error } }, null, 2));
process.exitCode = EXIT_CODES.USAGE_ERROR;
return;
}
const { focused, matches_n, match_level } = await page.focus(resolvedTarget, parsed.opts);
console.log(JSON.stringify({ focused, target: resolvedTarget, matches_n, match_level }, null, 2));
}));
addBrowserTabOption(
addSemanticLocatorOptions(browser.command('dblclick'))
.argument('[target]', 'Numeric ref (from browser state / find), CSS selector, or omit when using --role/--name/etc.')
.option('--nth <n>', 'When <target> is a multi-match CSS selector, pick the nth match (0-based)')
.description('Double-click element — JSON envelope {dblclicked, target, matches_n}'),
)View on GitHub (pinned to 49907e53dc)
Solutions
- Switch to a backend that implements focus (Playwright/Puppeteer-based).
- Fallback to `browser eval` calling `element.focus()` in page JavaScript.
- Verify backend configuration flags point at a full automation driver.
Example fix
// before
browser --backend minimal focus '#email'
// after
browser --backend playwright focus '#email'
// or: browser eval "document.querySelector('#email').focus()" Defensive patterns
Strategy: type-guard
Validate before calling
const page = await getBrowserPage();
if (typeof page.focus !== 'function') {
throw new Error('Current backend cannot focus elements');
} Type guard
function supportsFocus(page) {
return typeof page?.focus === 'function';
} Try / catch
try {
await run(['browser', 'focus', sel]);
} catch (err) {
if (String(err.message).includes('focus is not supported')) {
await run(['browser', 'eval', `document.querySelector('${sel}').focus()`]);
} else throw err;
} Prevention
- Check page.focus existence before focusing.
- Prefer full-featured backends for form interaction workflows.
- Use eval-based focus as a documented fallback.
- Keep backend adapters updated.
When it happens
Trigger: Running `browser focus [target]` against a backend whose page object does not implement `focus` (`typeof page.focus !== 'function'`).
Common situations: Minimal/limited browser backend drivers, restricted automation adapters, or misconfigured backend selection in CLI options/env.
Related errors
- browser hover is not supported by this browser backend
- browser dblclick is not supported by this browser backend
- browser ${checked ? 'check' : 'uncheck'} is not supported by
- browser upload is not supported by this browser backend
- browser drag is not supported by this browser backend
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/5d0e98194118c50c.
Report an issue: GitHub.