{"record":{"id":"7cb3a0b897d07b8d","repo":"jackwener/OpenCLI","slug":"could-not-insert-text","errorCode":null,"errorMessage":"Could not insert text.","messagePattern":"Could not insert text\\.","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/weibo/publish.js","lineNumber":226,"sourceCode":"                        if (t.offsetParent !== null) ta = t;\n                    }\n                }\n                if (!ta) return { ok: false, message: 'textarea not visible' };\n                ta.focus();\n                const nativeSetter = Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, 'value')?.set;\n                if (nativeSetter) {\n                    nativeSetter.call(ta, textContent);\n                } else {\n                    ta.value = textContent;\n                }\n                ta.dispatchEvent(new Event('input', { bubbles: true }));\n                ta.dispatchEvent(new Event('change', { bubbles: true }));\n                return { ok: true, valueLength: ta.value.length };\n            })(${JSON.stringify(TEXTAREA_SELECTORS)})\n        `, { textContent: text });\n\n        if (!insertResult?.ok) {\n            throw new CommandExecutionError(insertResult?.message ?? 'Could not insert text.');\n        }\n\n\n        // Step 7: Click the send button inside the compose editor\n        // Try 发送 first (compose editor's submit), then 发布 (fallback)\n        await page.wait({ time: 0.5 });\n        const publishResult = await page.evaluate(`\n            () => {\n                const visible = el => !!el && el.offsetParent !== null && !el.disabled;\n                const labels = ['发送', '发布'];\n                for (const label of labels) {\n                    const allBtns = document.querySelectorAll('button, [role=\"button\"]');\n                    for (const btn of allBtns) {\n                        const t = (btn.innerText || btn.textContent || '').trim();\n                        if (t === label && visible(btn)) {\n                            btn.click();\n                            return { ok: true, label };\n                        }","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/weibo/publish.js#L208-L244","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Retry — transient re-render races are the usual cause","Update the CLI to a build with current TEXTAREA_SELECTORS","Check weibo.com manually for interstitial dialogs (login, verification) blocking the compose editor","Report/patch the selector list if Weibo shipped a new UI"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    await publishToWeibo(text);\n} catch (err) {\n    if (String(err.message).includes('Could not insert text')) {\n        await new Promise(r => setTimeout(r, 2000));\n        await publishToWeibo(text); // editor may have needed more time to render\n    } else throw err;\n}","preventionTips":["Retry after short backoff — compose-editor render races are transient","Ensure no interstitial login/verification dialogs are pending in the browser","Keep the CLI updated for current TEXTAREA_SELECTORS","Schedule automations with generous settle time after page load"],"tags":["dom-selector","ui-drift","weibo"],"backgroundTag":"selector-stale-dom","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}