{"record":{"id":"7293aa732a7a6c91","repo":"jackwener/OpenCLI","slug":"could-not-prepare-fieldname-input-debug-screen","errorCode":null,"errorMessage":"Could not prepare ${fieldName} input. Debug screenshot: /tmp/xhs_publish_${fieldName}_debug.png","messagePattern":"Could not prepare (.+?) input\\. Debug screenshot: /tmp/xhs_publish_(.+?)_debug\\.png","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"clis/xiaohongshu/publish.js","lineNumber":367,"sourceCode":"          }\n        };\n        const el = Array.from(document.querySelectorAll(selector)).find(node => node && node.offsetParent !== null);\n        if (!el) return { ok: false };\n        el.focus();\n        el.textContent = '';\n        const selection = window.getSelection();\n        const range = document.createRange();\n        range.selectNodeContents(el);\n        range.collapse(false);\n        selection?.removeAllRanges();\n        selection?.addRange(range);\n        fireBeforeInput(el, nextText);\n        return { ok: true };\n      })(${JSON.stringify(located.sel)}, ${JSON.stringify(text)})\n    `);\n        if (!prepared?.ok) {\n            await page.screenshot({ path: `/tmp/xhs_publish_${fieldName}_debug.png` });\n            throw new Error(`Could not prepare ${fieldName} input. Debug screenshot: /tmp/xhs_publish_${fieldName}_debug.png`);\n        }\n        try {\n            await page.insertText(text);\n            result = await page.evaluate(`\n      ((selector, expectedText) => {\n        const __opencli_xhs_fill_phase = \"verify\";\n        const normalize = (value) => (value || '').replace(/\\\\s+/g, ' ').trim();\n        const fireInput = (el, value) => {\n          try {\n            el.dispatchEvent(new InputEvent('input', {\n              bubbles: true,\n              data: value,\n              inputType: 'insertText',\n            }));\n          } catch {\n            el.dispatchEvent(new Event('input', { bubbles: true }));\n          }\n        };","sourceCodeStart":349,"sourceCodeEnd":385,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xiaohongshu/publish.js#L349-L385","documentation":"Thrown by fillField when the 'prepare' phase (focusing the located input and firing beforeinput events) fails — prepared.ok was falsy — meaning the editor element was found but could not be put into a state to receive text. A debug screenshot is saved first.","triggerScenarios":"Editor is contenteditable but focus is stolen by an overlay/modal; shadow-DOM or iframe boundary prevents the script from mutating the element; page re-rendered between locate and prepare; anti-bot script interfering with synthetic events.","commonSituations":"XHS shows a popup/dialog over the editor; slow page replaced DOM mid-fill; running in an unusual browser build where CDP input events behave differently.","solutions":["Inspect /tmp/xhs_publish_<field>_debug.png for overlays, dialogs, or login prompts.","Dismiss any modals/cookies dialogs on the publish page before publishing.","Retry with longer waits so the page settles before filling.","Update the CLI in case XHS changed its editor structure."],"exampleFix":"// before\nawait xhs.publish({ ... }); // fails when a modal covers the editor\n// after\ntry {\n  await xhs.publish({ ... });\n} catch (e) {\n  if (e.message.includes('Could not prepare')) {\n    // dismiss modal, then retry\n    await publish();\n  }\n}","handlingStrategy":"retry","validationCode":"// dismiss blocking overlays beforehand if your wrapper exposes it\nawait page.evaluate(() => document.querySelectorAll('.modal, .dialog').forEach(el => el.remove()));","typeGuard":null,"tryCatchPattern":"try {\n  await xhs.publish(opts);\n} catch (err) {\n  if (err.message.includes('Could not prepare')) {\n    inspectScreenshot('/tmp/xhs_publish_debug.png');\n    return retryPublish(opts);\n  }\n  throw err;\n}","preventionTips":["Ensure no modals/dialogs cover the editor","Wait for full page load before publishing","Avoid mid-publish page interactions from other scripts","Retry once on this transient failure before giving up"],"tags":["puppeteer","automation","dom","xiaohongshu"],"backgroundTag":"selector-not-found","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}