{"record":{"id":"0b19b9a104a18943","repo":"jackwener/OpenCLI","slug":"label-could-not-verify-current-composer-media","errorCode":null,"errorMessage":"${label}: could not verify current composer media count","messagePattern":"(.+?): could not verify current composer media count","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/xiaohongshu/publish.js","lineNumber":1038,"sourceCode":"        for (const el of Array.from(root.querySelectorAll('img, video, canvas, [style*=\"background-image\"]'))) {\n          if (!visibleMedia(el)) continue;\n          const rect = el.getBoundingClientRect();\n          const src = el.currentSrc || el.src || el.getAttribute('src') || el.style?.backgroundImage || '';\n          const key = src || String(Math.round(rect.left)) + ':' + String(Math.round(rect.top));\n          if (seen.has(key)) continue;\n          seen.add(key);\n          count += 1;\n        }\n      }\n      return { ok: true, count };\n    })()\n  `);\n    return unwrapBrowserResult(result);\n}\nasync function assertComposerMediaCount(page, expectedCount, label) {\n    const state = await currentComposerMediaCount(page);\n    if (!state || typeof state.count !== 'number') {\n        throw new CommandExecutionError(`${label}: could not verify current composer media count`);\n    }\n    if (state.count < expectedCount) {\n        await page.screenshot({ path: '/tmp/xhs_publish_media_debug.png' });\n        throw new CommandExecutionError(`${label}: expected at least ${expectedCount} visible media item(s), got ${state.count}. ` +\n            'Debug screenshot: /tmp/xhs_publish_media_debug.png');\n    }\n}\n/**\n * Drive the full 文字配图 sub-flow: entry → type cards → 生成图片 → pick style → 下一步.\n * Leaves the page on the standard editor (caller then runs waitForEditForm).\n */\nasync function runTextImageFlow(page, cards, cardStyle) {\n    const entry = await clickByText(page, TEXT_IMAGE_ENTRY_LABEL);\n    if (!entry?.ok) {\n        await page.screenshot({ path: '/tmp/xhs_publish_textimage_debug.png' });\n        throw new CommandExecutionError(`文字配图: could not click \"${TEXT_IMAGE_ENTRY_LABEL}\" entry. ` +\n            'Debug: /tmp/xhs_publish_textimage_debug.png');\n    }","sourceCodeStart":1020,"sourceCodeEnd":1056,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xiaohongshu/publish.js#L1020-L1056","documentation":"assertComposerMediaCount calls currentComposerMediaCount to count visible media items in the composer. If the count query returns nothing usable (no numeric count), it throws this error — the media count could not be verified at all, distinct from the count being too low.","triggerScenarios":"currentComposerMediaCount's page.evaluate returns null/undefined/non-numeric — evaluate threw and was swallowed, the composer DOM selectors matched nothing, or the browser result could not be unwrapped.","commonSituations":"Publish page not fully loaded when the assertion runs; XHS DOM restructure broke the media-count selectors; browser evaluate failed due to a closed CDP session or closed shadow-root access assumptions; running against a step where no composer exists.","solutions":["Add a wait for the editor/composer to render before media-count assertions run.","Retry the publish — transient evaluate failures are common.","Check the browser session is still alive (a dead session makes every evaluate fail).","If persistent, update currentComposerMediaCount's selectors for the current XHS composer DOM."],"exampleFix":"// before\nawait assertComposerMediaCount(page, media.length, \"发布\");\n// after\nawait page.wait({ time: 2.0 }); // ensure composer rendered\ntry {\n  await assertComposerMediaCount(page, media.length, \"发布\");\n} catch (e) {\n  if (!/could not verify/.test(e.message)) throw e;\n  await page.wait({ time: 3.0 });\n  await assertComposerMediaCount(page, media.length, \"发布\");\n}","handlingStrategy":"retry","validationCode":"await page.wait({ time: 2.0 }); // composer must be rendered before counting","typeGuard":"null","tryCatchPattern":"try { await assertComposerMediaCount(page, n, label); }\ncatch (e) {\n  if (/could not verify/.test(e.message)) {\n    await page.wait({ time: 3.0 });\n    await assertComposerMediaCount(page, n, label);\n  } else throw e;\n}","preventionTips":["Wait for the composer to render before media assertions","Ensure the browser/CDP session is alive before evaluate calls","Keep media-count selectors updated against XHS DOM changes"],"tags":["browser-automation","dom-selector","verification"],"backgroundTag":"dom-query-returned-null","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}