{"record":{"id":"e0567eee04972b93","repo":"jackwener/OpenCLI","slug":"chatgpt-model-selection-requires-native-browser-cl","errorCode":null,"errorMessage":"ChatGPT model selection requires native browser click support.","messagePattern":"ChatGPT model selection requires native browser click support\\.","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/chatgpt/utils.js","lineNumber":565,"sourceCode":"    await page.evaluate(`(() => {\n        const value = encodeURIComponent(JSON.stringify({ model: ${JSON.stringify(modelSlug)}, effort: ${JSON.stringify(effort)} }));\n        for (const domain of ['; domain=.chatgpt.com', '; domain=chatgpt.com', '']) {\n            document.cookie = 'oai-last-model-config=; path=/' + domain + '; max-age=0; SameSite=Lax';\n        }\n        document.cookie = 'oai-last-model-config=' + value + '; path=/; domain=.chatgpt.com; max-age=31536000; SameSite=Lax';\n        document.cookie = 'oai-last-model-config=' + value + '; path=/; max-age=31536000; SameSite=Lax';\n        if (window.location.pathname === '/new') window.location.reload();\n        else window.location.assign('/new');\n        return true;\n    })()`).catch(() => true);\n    return { ok: true, status: response.status, modelSlug, effort };\n}\n\nexport async function selectChatGPTModel(page, model) {\n    const target = requireKnownChatGPTModel(model);\n    debugChatGPTModel(`target=${target.key}`);\n    if (typeof page.nativeClick !== 'function') {\n        throw new CommandExecutionError('ChatGPT model selection requires native browser click support.');\n    }\n    await ensureOnChatGPT(page);\n    debugChatGPTModel('ensured chatgpt');\n    const currentUrl = await currentChatGPTUrl(page).catch(() => '');\n    debugChatGPTModel(`url=${currentUrl}`);\n    if (!currentUrl.startsWith(`${CHATGPT_URL}/new`)) {\n        await page.goto(`${CHATGPT_URL}/new`, { waitUntil: 'none' });\n        await page.wait(2);\n    }\n    await ensureChatGPTComposer(page, 'ChatGPT model selection requires a logged-in ChatGPT session with a visible composer.');\n    debugChatGPTModel('composer ok');\n\n    const before = await getCurrentChatGPTModel(page);\n    debugChatGPTModel(`before=${before.model || 'none'}`);\n    if (before.model === target.key) {\n        return { Status: 'Already selected', Model: target.label };\n    }\n    const apiResult = await setChatGPTModelConfig(page, target);","sourceCodeStart":547,"sourceCodeEnd":583,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/chatgpt/utils.js#L547-L583","documentation":"selectChatGPTModel performs real UI clicks on the ChatGPT page, which requires the page adapter to expose a nativeClick function (CDP-level mouse input). If page.nativeClick is not a function, the browser driver lacks that capability and the library throws CommandExecutionError before touching the page.","triggerScenarios":"Calling selectChatGPTModel with a page object from a driver/environment that does not implement nativeClick — e.g. a stubbed/mock page in tests, a headless driver missing input-injection support, or a page object from a different automation library that only supports evaluate().","commonSituations":"Swapping the underlying browser driver or upgrading it to a version without the nativeClick extension; unit tests injecting a minimal page fake; running in an environment where CDP input domains are disabled (some restricted/remote browser setups).","solutions":["Use the OpenCLI CDP browser automation page object, which implements nativeClick.","Upgrade/repair the browser driver so CDP Input domain (mouse events) is available.","In tests, add a nativeClick(x, y) no-op or simulated implementation to the page stub.","If native clicks can't be supported, set the model via the ChatGPT UI manually or use setChatGPTModelConfig directly where the session permits."],"exampleFix":"// before\nconst page = await someLib.open('https://chatgpt.com'); // no nativeClick\nawait selectChatGPTModel(page, 'advanced');\n// after\nif (typeof page.nativeClick !== 'function') {\n  page = await opencli.browser.open('https://chatgpt.com'); // CDP page with nativeClick\n}\nawait selectChatGPTModel(page, 'advanced');","handlingStrategy":"type-guard","validationCode":"if (typeof page.nativeClick !== 'function') {\n  throw new Error('This browser driver does not support native clicks; use the OpenCLI CDP page.');\n}","typeGuard":"function supportsNativeClick(page) {\n  return page != null && typeof page.nativeClick === 'function'\n    && typeof page.evaluate === 'function';\n}","tryCatchPattern":"try {\n  await selectChatGPTModel(page, model);\n} catch (err) {\n  if (err instanceof CommandExecutionError && /native browser click support/.test(err.message)) {\n    page = await opencli.browser.open(page.url()); // reopen with CDP driver\n    return selectChatGPTModel(page, model);\n  }\n  throw err;\n}","preventionTips":["Always obtain the page object from the OpenCLI CDP automation API.","Guard driver upgrades with a smoke test asserting nativeClick exists.","Extend test fakes with a nativeClick implementation to avoid CI surprises.","Verify remote browser setups allow CDP input injection."],"tags":["browser-automation","capability-check","chatgpt","cdp"],"backgroundTag":"missing-browser-capability","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}