jackwener/OpenCLI · error · CommandExecutionError
Failed to fill content
Error message
Failed to fill content
What it means
This CommandExecutionError is thrown when fillContent() fails to insert the article body. fillContent queries div[contenteditable="true"] elements and picks the last one; if none exists it returns {ok:false, reason:'content editor not found'}, which the command surfaces as this error. It means the rich-text contenteditable editor was absent when the content step ran.
Source
Thrown at clis/weixin/create-draft.js:304
{ name: 'cover-image', help: '封面图片路径 (会先上传到正文再设为封面)' },
{ name: 'summary', help: '文章摘要' },
{ name: 'timeout', type: 'int', required: false, default: 180, help: 'Max seconds for the overall command (default: 180)' },
],
columns: ['status', 'detail'],
func: async (page, kwargs) => {
try {
const coverImage = kwargs['cover-image'] ? resolveCoverImage(kwargs['cover-image']) : null;
await navigateToEditor(page);
const titleResult = await fillField(page, 'textarea#title', kwargs.title);
if (!titleResult?.ok) throw new CommandExecutionError('Failed to fill title');
if (kwargs.author) {
const authorResult = await fillField(page, 'input#author', kwargs.author);
if (!authorResult?.ok) throw new CommandExecutionError('Failed to fill author');
}
const contentResult = await fillContent(page, kwargs.content);
if (!contentResult?.ok) throw new CommandExecutionError('Failed to fill content');
if (coverImage) {
await uploadContentImage(page, coverImage);
const coverSet = await selectCoverFromContent(page);
if (coverSet !== true) {
throw new CommandExecutionError('WeChat uploaded the image but did not confirm it as the draft cover.');
}
}
if (kwargs.summary) {
const summaryResult = await fillField(page, 'textarea#js_description', kwargs.summary);
if (!summaryResult?.ok) throw new CommandExecutionError('Failed to fill summary');
}
await saveDraft(page);
return [{
status: 'draft saved',
detail: `"${kwargs.title}"${kwargs.author ? ` by ${kwargs.author}` : ''}${coverImage ? ' (with cover)' : ''}`,View on GitHub (pinned to 49907e53dc)
Solutions
- Retry — UEditor async initialization past the fixed 4s wait is the most common cause.
- Inspect the live editor and confirm a div[contenteditable="true"] exists; update fillContent()'s selector strategy in clis/weixin/create-draft.js if WeChat changed the editor.
- Wait explicitly for the contenteditable editor (or #ueditor_0) to appear before calling fillContent.
- Check whether content contains characters that break the JSON.stringify-injected execCommand('insertText') path; test with plain ASCII content to isolate.
Example fix
// before
const contentResult = await fillContent(page, kwargs.content);
if (!contentResult?.ok) throw new CommandExecutionError('Failed to fill content');
// after
await page.waitForSelector('div[contenteditable="true"]', { timeout: 15000 });
const contentResult = await fillContent(page, kwargs.content);
if (!contentResult?.ok) throw new CommandExecutionError('Failed to fill content: ' + (contentResult?.reason ?? 'unknown')); Defensive patterns
Strategy: validation
Validate before calling
const editorReady = await page.evaluate('document.querySelectorAll("div[contenteditable=true]").length > 0');
if (editorReady !== true) throw new Error('Content editor not initialized; wait or re-navigate before filling content.'); Try / catch
try {
await createDraft({ title, content });
} catch (e) {
if (e instanceof CommandExecutionError && /Failed to fill content/.test(e.message)) {
// retry after a longer delay (UEditor async init), or fail fast with a clear message
} else throw e;
} Prevention
- Keep article content free of characters that could break the injected script; test with plain text first.
- Allow extra initial load time on first run of the day or on large accounts (UEditor initializes slowly).
- Verify the contenteditable editor still exists in the DOM after WeChat editor updates.
- Prefer an explicit wait-for-selector over fixed sleeps in any local modification.
When it happens
Trigger: Calling create-draft when no div[contenteditable="true"] element is present in the editor DOM: the UEditor rich-text iframe/instance has not initialized within the fixed 4-second wait, WeChat changed the editor implementation (no longer a contenteditable div), or the page served is a degraded/variant editor.
Common situations: UEditor initializes asynchronously and slowly on first load or large accounts, so the contenteditable node is not yet attached; WeChat rolls out a new editor (e.g., a ProseMirror-based one) removing the contenteditable div; heavy content in kwargs.content times out execCommand-based insertion indirectly by racing page state; proxy or slow network delays page load.
Related errors
- Failed to fill title
- Failed to fill author
- Failed to fill summary
- Instagram reel upload failed
- Instagram reel preview did not appear after upload
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/1f5165f210050f0d.
Report an issue: GitHub.