jackwener/OpenCLI · error · CommandExecutionError
Failed to fill Instagram caption
Error message
Failed to fill Instagram caption
What it means
fillCaption evaluates in-page JS that types/sets the caption content into the editor and returns { ok:false } on failure; the library then throws this error. It means the caption text could not be entered into the editor element.
Source
Thrown at clis/instagram/post.js:1168
const range = document.createRange();
range.selectNodeContents(editor);
selection.addRange(range);
}
const dt = new DataTransfer();
dt.setData('text/plain', content);
editor.dispatchEvent(new ClipboardEvent('paste', {
clipboardData: dt,
bubbles: true,
cancelable: true,
}));
return { ok: true, mode: 'contenteditable', value: editor.textContent || '' };
}
return { ok: false };
})(${JSON.stringify(content)})
`);
if (!result?.ok) {
throw new CommandExecutionError('Failed to fill Instagram caption');
}
}
async function captionMatches(page, content) {
const result = await page.evaluate(`
((content) => {
const normalized = content.trim();
const readLexicalText = (node) => {
if (!node || typeof node !== 'object') return '';
if (node.type === 'text' && typeof node.text === 'string') return node.text;
if (!Array.isArray(node.children)) return '';
if (node.type === 'root') {
return node.children.map((child) => readLexicalText(child)).join('\\n');
}
if (node.type === 'paragraph') {
return node.children.map((child) => readLexicalText(child)).join('');
}
return node.children.map((child) => readLexicalText(child)).join('');
};View on GitHub (pinned to 49907e53dc)
Solutions
- Retry the post; focus-stealing dropdowns are often transient
- Simplify the caption (strip unusual emoji or control characters) to test whether content is the cause
- Screenshot the editor state to confirm the caption editor is still open
- Update the CLI if the caption-fill script no longer matches the editor element
Example fix
// before
await fillCaption(page, 'Launch day! \u{1F680}\u200D\u{1F4A5} #now'); // ZWJ sequence
// after
await fillCaption(page, 'Launch day! 🚀 #now'); // simpler caption fills cleanly Defensive patterns
Strategy: try-catch
Validate before calling
if ([...content].length > 2200) throw new Error('Caption exceeds Instagram limit'); Type guard
function isFillableCaption(s) { return typeof s === 'string' && s.trim().length > 0 && [...s].length <= 2200; } Try / catch
try {
await fillCaption(page, content);
} catch (e) {
if (String(e.message).includes('Failed to fill Instagram caption')) {
await page.evaluate(() => document.activeElement?.blur());
await page.wait({ time: 1 });
await fillCaption(page, content);
} else throw e;
} Prevention
- Keep captions within the 2,200-character limit
- Test captions with complex emoji separately before production runs
- Blur/close suggestion dropdowns before filling the editor
When it happens
Trigger: The caption-fill page.evaluate returns ok:false — editor element not found, contenteditable not focusable, or the set-value script was rejected by the page.
Common situations: Editor is a contenteditable that rejects direct value assignment, emoji/unicode caption tripping the injection script, an emoji picker or suggestion dropdown stealing focus, or a page navigation mid-fill.
Related errors
- Instagram image preview did not appear after upload
- Instagram action button not found: ${labels.join(' / ')}
- Instagram caption editor did not appear
- Instagram caption did not stick before sharing
- Instagram action button not found: ${labels.join(' / ')}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/67148d9b1ccc2f9a.
Report an issue: GitHub.