{"record":{"id":"50ec546141d05ef5","repo":"jackwener/OpenCLI","slug":"gemini-image-detection-returned-a-malformed-result","errorCode":null,"errorMessage":"Gemini image detection returned a malformed result","messagePattern":"Gemini image detection returned a malformed result","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/gemini/utils.js","lineNumber":2367,"sourceCode":"        const width = img.naturalWidth || img.width || 0;\n        const height = img.naturalHeight || img.height || 0;\n        if (!src) continue;\n        if (alt.includes('avatar') || alt.includes('logo') || alt.includes('icon')) continue;\n        // A placeholder still streaming its bytes reports complete false and\n        // naturalWidth 0 while laying out at full size, so the size gate below\n        // would accept it and the export step would save a blank frame (#2245).\n        if (!img.complete || !img.naturalWidth) continue;\n        if (width < 128 && height < 128) continue;\n        if (seen.has(src)) continue;\n        seen.add(src);\n        urls.push(src);\n      }\n      return urls;\n    })()\n  `);\n    const urls = requireGeminiArrayResult(result, 'Gemini image detection');\n    if (!urls.every((url) => typeof url === 'string')) {\n        throw new CommandExecutionError('Gemini image detection returned a malformed result');\n    }\n    return urls;\n}\n/** Cheap generation probe: the snapshot read walks the whole transcript. */\nexport async function isGeminiGenerating(page) {\n    let result;\n    try {\n        result = await page.evaluate(`(() => ${isGeneratingExpression()})()`);\n    }\n    catch (error) {\n        const message = error instanceof Error ? error.message : String(error);\n        throw new CommandExecutionError('Gemini generation probe failed', message);\n    }\n    const value = unwrapGeminiEvaluateResult(result, 'Gemini generation probe');\n    if (typeof value !== 'boolean') {\n        throw new CommandExecutionError('Gemini generation probe returned a malformed result');\n    }\n    return value;","sourceCodeStart":2349,"sourceCodeEnd":2385,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/gemini/utils.js#L2349-L2385","documentation":"Thrown when the image-detection page.evaluate returns a non-array (caught by requireGeminiArrayResult with label 'Gemini image detection') or an array containing non-string URLs. The library extracts generated-image URLs from the response DOM and validates the shape before returning them to callers like waitForGeminiImages.","triggerScenarios":"Calling image extraction/waitForGeminiImages when the in-page script returns undefined/null instead of an array (script error, no conversation DOM) or rows that are objects/null instead of URL strings — usually because Gemini changed how generated images are embedded (new container, blob URLs, srcset).","commonSituations":"Gemini UI update to image carousels; page polled before any response rendered; conversation using an image format the extractor doesn't recognize; evaluate unwrapping producing undefined on script exception.","solutions":["Wait until the assistant response has fully rendered before extracting images (use waitForGeminiTranscript first).","Log the raw evaluate result and update the image-extraction script selectors to the current Gemini image DOM.","Coerce entries to strings (img.src) and filter nulls inside the in-page script.","Catch CommandExecutionError and treat as 'no images yet', retrying with the existing poll loop."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isImageUrlArray(v) {\n  return Array.isArray(v) && v.every((u) => typeof u === 'string' && /^https?:|^data:|^blob:/.test(u));\n}","tryCatchPattern":"try {\n  urls = await getGeminiImageUrls(page);\n} catch (e) {\n  if (String(e.message).includes('malformed result')) urls = []; // no images yet\n  else throw e;\n}","preventionTips":["Only extract images after the assistant response fully rendered.","Run waitForGeminiTranscript before image polling.","Update image-extraction selectors when Gemini changes image embedding.","Treat empty/malformed results as 'no images' in polling loops."],"tags":["gemini","dom-scraping","schema-validation","images"],"backgroundTag":"schema-validation-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}