{"record":{"id":"5d0e98194118c50c","repo":"jackwener/OpenCLI","slug":"browser-focus-is-not-supported-by-this-browser-bac","errorCode":null,"errorMessage":"browser focus is not supported by this browser backend","messagePattern":"browser focus is not supported by this browser backend","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cli.ts","lineNumber":2127,"sourceCode":"      if (!resolvedTarget) return;\n      const parsed = nthToResolveOpts(opts?.nth);\n      if ('error' in parsed) {\n        console.log(JSON.stringify({ error: { code: 'usage_error', message: parsed.error } }, null, 2));\n        process.exitCode = EXIT_CODES.USAGE_ERROR;\n        return;\n      }\n      const { matches_n, match_level } = await page.hover(resolvedTarget, parsed.opts);\n      console.log(JSON.stringify({ hovered: true, target: resolvedTarget, matches_n, match_level }, null, 2));\n    }));\n\n  addBrowserTabOption(\n    addSemanticLocatorOptions(browser.command('focus'))\n      .argument('[target]', 'Numeric ref (from browser state / find), CSS selector, or omit when using --role/--name/etc.')\n      .option('--nth <n>', 'When <target> is a multi-match CSS selector, pick the nth match (0-based)')\n      .description('Focus an element — JSON envelope {focused, target, matches_n}'),\n  )\n    .action(browserAction(async (page, target, opts) => {\n      if (typeof page.focus !== 'function') throw new Error('browser focus is not supported by this browser backend');\n      const resolvedTarget = await resolveWriteTargetOrPrint(page, target, opts ?? {});\n      if (!resolvedTarget) return;\n      const parsed = nthToResolveOpts(opts?.nth);\n      if ('error' in parsed) {\n        console.log(JSON.stringify({ error: { code: 'usage_error', message: parsed.error } }, null, 2));\n        process.exitCode = EXIT_CODES.USAGE_ERROR;\n        return;\n      }\n      const { focused, matches_n, match_level } = await page.focus(resolvedTarget, parsed.opts);\n      console.log(JSON.stringify({ focused, target: resolvedTarget, matches_n, match_level }, null, 2));\n    }));\n\n  addBrowserTabOption(\n    addSemanticLocatorOptions(browser.command('dblclick'))\n      .argument('[target]', 'Numeric ref (from browser state / find), CSS selector, or omit when using --role/--name/etc.')\n      .option('--nth <n>', 'When <target> is a multi-match CSS selector, pick the nth match (0-based)')\n      .description('Double-click element — JSON envelope {dblclicked, target, matches_n}'),\n  )","sourceCodeStart":2109,"sourceCodeEnd":2145,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/src/cli.ts#L2109-L2145","documentation":"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.","triggerScenarios":"Running `browser focus [target]` against a backend whose page object does not implement `focus` (`typeof page.focus !== 'function'`).","commonSituations":"Minimal/limited browser backend drivers, restricted automation adapters, or misconfigured backend selection in CLI options/env.","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."],"exampleFix":"// before\nbrowser --backend minimal focus '#email'\n// after\nbrowser --backend playwright focus '#email'\n// or: browser eval \"document.querySelector('#email').focus()\"","handlingStrategy":"type-guard","validationCode":"const page = await getBrowserPage();\nif (typeof page.focus !== 'function') {\n  throw new Error('Current backend cannot focus elements');\n}","typeGuard":"function supportsFocus(page) {\n  return typeof page?.focus === 'function';\n}","tryCatchPattern":"try {\n  await run(['browser', 'focus', sel]);\n} catch (err) {\n  if (String(err.message).includes('focus is not supported')) {\n    await run(['browser', 'eval', `document.querySelector('${sel}').focus()`]);\n  } else throw err;\n}","preventionTips":["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."],"tags":["browser","cli","capability"],"backgroundTag":"unsupported-browser-capability","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}