{"record":{"id":"c80a43c85fe7703a","repo":"jackwener/OpenCLI","slug":"failed-to-send-image-prompt-to-chatgpt","errorCode":null,"errorMessage":"Failed to send image prompt to ChatGPT","messagePattern":"Failed to send image prompt to ChatGPT","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/chatgpt/image.js","lineNumber":119,"sourceCode":"        }\n        await clearChatGPTDraft(page);\n\n        if (imagePaths.length) {\n            let upload;\n            try {\n                upload = await uploadChatGPTImages(page, preparedImages.paths);\n            } catch (err) {\n                throw new CommandExecutionError(`Failed to upload image to ChatGPT: ${err instanceof Error ? err.message : String(err)}`);\n            }\n            if (!upload?.ok) throw new CommandExecutionError(upload?.reason || 'Failed to upload image to ChatGPT');\n        }\n\n        const beforeUrls = await getChatGPTVisibleImageUrls(page);\n\n        // Send an explicit generation/editing prompt so ChatGPT returns image assets.\n        const sent = await sendChatGPTMessage(page, buildPrompt(prompt, imagePaths.length));\n        if (!sent) {\n            throw new CommandExecutionError(\n                'Failed to send image prompt to ChatGPT',\n                `Open ${await currentChatGPTLink(page)} and verify the composer is ready.`,\n            );\n        }\n\n        // ChatGPT briefly navigates to /c/{id} after sending, then may\n        // redirect back to the home page. Poll until we capture the /c/ URL.\n        let convUrl = '';\n        for (let ci = 0; ci < 10; ci++) {\n            const url = await currentChatGPTLink(page);\n            if (url.includes('/c/')) { convUrl = url; break; }\n            await page.sleep(2);\n        }\n        if (!convUrl) {\n            convUrl = await currentChatGPTLink(page);\n        }\n\n        const urls = await waitForChatGPTImages(page, beforeUrls, timeout, convUrl);","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/chatgpt/image.js#L101-L137","documentation":"After uploading attachments (if any), the command sends the prompt via sendChatGPTMessage; if it returns falsy, the composer submit did not register and the command throws CommandExecutionError('Failed to send image prompt to ChatGPT') with remediation pointing at the current conversation URL. It guards against silently generating nothing.","triggerScenarios":"`opencli chatgpt image \"prompt\"` where sendChatGPTMessage returns false — composer not ready, send button disabled, text insertion failed, a modal/dialog intercepting input, or the page navigated at the moment of submit.","commonSituations":"Composer still loading after page.goto('/new') with only 2s settle; leftover draft or an unread dialog covering the composer; ChatGPT rate limits / usage cap disabling the send button; stale session showing a login interstitial; UI change altering the submit control.","solutions":["Follow the error's hint: open the printed URL and verify the composer works manually.","Retry — first-load hydration races commonly cause a one-off failure.","Re-login / refresh the session cookie, then retry.","Clear any leftover draft/dialog state in the persistent browser profile.","If it never sends, the composer selectors changed — update the library."],"exampleFix":"// before\nopencli chatgpt image \"a lighthouse\"   # sends immediately after goto with 2s settle\n// after\n# warm up the page first in the persistent session, then retry\nopencli chatgpt image \"a lighthouse\"   # second attempt after composer confirmed ready","handlingStrategy":"retry","validationCode":"// Verify the session is logged in and the composer is usable before sending\nawait run('chatgpt history', '--limit', '1'); // throws/logs if the session is dead","typeGuard":"null","tryCatchPattern":"async function sendWithRetry(prompt, attempt = 0) {\n  try {\n    return await run('chatgpt image', prompt);\n  } catch (err) {\n    if (String(err.message).includes('Failed to send image prompt to ChatGPT') && attempt < 2) {\n      await sleep(20_000 * (attempt + 1));\n      return sendWithRetry(prompt, attempt + 1);\n    }\n    throw err;\n  }\n}","preventionTips":["Retry — the 2s post-goto settle often races composer hydration","Refresh login when the persistent session is stale","Dismiss leftover dialogs/drafts in the browser profile between runs","Watch ChatGPT usage caps that disable the send button","Update the library if composer selectors change"],"tags":["chatgpt","composer","command-execution"],"backgroundTag":"prompt-submit-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}