jackwener/OpenCLI · error · CommandExecutionError

Could not insert text.

Error message

Could not insert text.

What it means

Thrown when the compose textarea could not be filled: the DOM-insert routine returned ok:false with its own message, or nothing was returned at all. The command finds one of TEXTAREA_SELECTORS (placeholder '有什么新鲜事'/legacy class hash), sets the value with the native setter to preserve Weibo's Vue reactivity, and dispatches input/change events — if any step fails the post text would be missing, so it aborts.

Source

Thrown at clis/weibo/publish.js:226

                        if (t.offsetParent !== null) ta = t;
                    }
                }
                if (!ta) return { ok: false, message: 'textarea not visible' };
                ta.focus();
                const nativeSetter = Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, 'value')?.set;
                if (nativeSetter) {
                    nativeSetter.call(ta, textContent);
                } else {
                    ta.value = textContent;
                }
                ta.dispatchEvent(new Event('input', { bubbles: true }));
                ta.dispatchEvent(new Event('change', { bubbles: true }));
                return { ok: true, valueLength: ta.value.length };
            })(${JSON.stringify(TEXTAREA_SELECTORS)})
        `, { textContent: text });

        if (!insertResult?.ok) {
            throw new CommandExecutionError(insertResult?.message ?? 'Could not insert text.');
        }


        // Step 7: Click the send button inside the compose editor
        // Try 发送 first (compose editor's submit), then 发布 (fallback)
        await page.wait({ time: 0.5 });
        const publishResult = await page.evaluate(`
            () => {
                const visible = el => !!el && el.offsetParent !== null && !el.disabled;
                const labels = ['发送', '发布'];
                for (const label of labels) {
                    const allBtns = document.querySelectorAll('button, [role="button"]');
                    for (const btn of allBtns) {
                        const t = (btn.innerText || btn.textContent || '').trim();
                        if (t === label && visible(btn)) {
                            btn.click();
                            return { ok: true, label };
                        }

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Retry — transient re-render races are the usual cause
  2. Update the CLI to a build with current TEXTAREA_SELECTORS
  3. Check weibo.com manually for interstitial dialogs (login, verification) blocking the compose editor
  4. Report/patch the selector list if Weibo shipped a new UI
Defensive patterns

Strategy: retry

Try / catch

try {
    await publishToWeibo(text);
} catch (err) {
    if (String(err.message).includes('Could not insert text')) {
        await new Promise(r => setTimeout(r, 2000));
        await publishToWeibo(text); // editor may have needed more time to render
    } else throw err;
}

Prevention

When it happens

Trigger: page.evaluate insert script returns {ok:false,...} or null/undefined; e.g. no textarea matched any selector, or the element became detached before the setter ran.

Common situations: Weibo changed the compose editor markup (placeholder text or class hash) so no selector matches; the editor was closed or re-rendered between opening and text insertion; an overlapping modal (login prompt, verification dialog) covers the compose box.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/7cb3a0b897d07b8d. Report an issue: GitHub.