{"record":{"id":"8c8913e45dcf9179","repo":"jackwener/OpenCLI","slug":"this-browser-session-does-not-support-frame-target","errorCode":null,"errorMessage":"This browser session does not support frame-targeted evaluation","messagePattern":"This browser session does not support frame-targeted evaluation","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cli.ts","lineNumber":2518,"sourceCode":"  // ── Extract ──\n\n  addBrowserTabOption(\n    browser.command('eval')\n      .argument('<js>', 'JavaScript code')\n      .option('--frame <index>', 'Cross-origin iframe index from \"browser frames\"')\n      .description('Execute JS in page context, return result'),\n  )\n    .action(browserAction(async (page, js, opts) => {\n      let result: unknown;\n      if (opts.frame !== undefined) {\n        const frameIndex = Number.parseInt(opts.frame, 10);\n        if (!Number.isInteger(frameIndex) || frameIndex < 0) {\n          console.error(`Invalid frame index \"${opts.frame}\". Use a 0-based index from \"browser frames\".`);\n          process.exitCode = EXIT_CODES.USAGE_ERROR;\n          return;\n        }\n        if (!page.evaluateInFrame) {\n          throw new Error('This browser session does not support frame-targeted evaluation');\n        }\n        result = await page.evaluateInFrame(js, frameIndex);\n      } else {\n        result = await page.evaluate(js);\n      }\n      if (typeof result === 'string') console.log(result);\n      else console.log(JSON.stringify(result, null, 2));\n    }));\n\n  // ── Extract (content reading) ──\n  //\n  // `extract` answers the \"read this page\" question that `get html` / `get text`\n  // can't: denoise → markdown → paragraph-aware chunking. Agents walk long pages\n  // by passing back the `next_start_char` cursor instead of juggling selectors.\n\n  addBrowserTabOption(\n    browser.command('extract')\n      .option('--selector <css>', 'CSS selector scope; defaults to <main>/<article>/<body>')","sourceCodeStart":2500,"sourceCodeEnd":2536,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/src/cli.ts#L2500-L2536","documentation":"The `browser eval` command with a `--frame <index>` option requires `page.evaluateInFrame` to run JavaScript inside a specific iframe. When the backend does not implement frame-targeted evaluation, this capability error is thrown instead of silently evaluating in the wrong context.","triggerScenarios":"Running `browser eval <js> --frame 2` (or similar frame option) where `page.evaluateInFrame` is undefined; frame index validity is checked first, so this fires only when the index is a valid non-negative integer but the backend lacks the feature.","commonSituations":"Minimal/CDP-lite drivers without frame execution support; cross-origin iframes the driver cannot reach; older adapter versions before evaluateInFrame was added.","solutions":["Use a backend implementing evaluateInFrame (Playwright/Puppeteer with frame support).","Run the script without `--frame` and target the iframe's contentWindow from the main world via `browser eval` where same-origin.","Get a frame handle differently, e.g. enumerate frames with `browser frames` and use backend-specific frame APIs."],"exampleFix":"// before\nbrowser --backend minimal eval \"document.title\" --frame 0\n// after\nbrowser --backend playwright eval \"document.title\" --frame 0","handlingStrategy":"type-guard","validationCode":"const frameIndex = Number(opts.frame);\nconst page = await getBrowserPage();\nif (Number.isInteger(frameIndex) && frameIndex >= 0 && typeof page.evaluateInFrame !== 'function') {\n  throw new Error('Backend lacks frame-targeted evaluation; drop --frame or switch backends');\n}","typeGuard":"function supportsFrameEval(page) {\n  return typeof page?.evaluateInFrame === 'function';\n}","tryCatchPattern":"try {\n  await run(['browser', 'eval', js, '--frame', String(i)]);\n} catch (err) {\n  if (String(err.message).includes('frame-targeted evaluation')) {\n    await run(['browser', 'eval', `(()=>{const f=document.querySelectorAll('iframe')[${i}];return f.contentDocument.title})()`]);\n  } else throw err;\n}","preventionTips":["Only pass --frame when the backend implements evaluateInFrame.","Check same-origin access to iframes before evaluating inside them.","Use `browser frames` to confirm the index exists.","Fall back to main-world contentWindow access for same-origin frames."],"tags":["browser","cli","capability","iframe"],"backgroundTag":"unsupported-browser-capability","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}