jackwener/OpenCLI · error · CommandExecutionError
Could not attach topic "${topic}": page.insertText is unavai
Error message
Could not attach topic "${topic}": page.insertText is unavailable What it means
CommandExecutionError guard in addTopics: typing the inline '#topic' query requires page.insertText (CDP Input.insertText) because legacy execCommand does not trigger XHS's keyup listener and no suggestion dropdown appears. If the browser-bridge wrapper lacks insertText, the topic cannot be attached reliably, so it throws instead of silently skipping.
Source
Thrown at clis/xiaohongshu/publish.js:591
for (const topic of topics) {
const focused = await focusBodyEnd(page, bodySelectors);
if (!focused) {
throw new CommandExecutionError(`Could not attach topic "${topic}": body editor not found`);
}
const beforeMarkerCount = Number(unwrapBrowserResult(await page.evaluate(topicMarkerCountScript(topic, bodySelectors)))) || 0;
// Separate this topic from the preceding text so the dropdown is clean.
if (typeof page.pressKey === 'function') {
try {
await page.pressKey('Enter');
}
catch { /* non-fatal */ }
}
// Type the inline "#<topic>" query so XHS pops the inline suggestion
// dropdown. We must use `page.insertText` (CDP) rather than the legacy
// `execCommand` path, otherwise XHS's editor doesn't fire its keyup
// listener and no dropdown appears.
if (typeof page.insertText !== 'function') {
throw new CommandExecutionError(`Could not attach topic "${topic}": page.insertText is unavailable`);
}
try {
await page.insertText(`#${topic}`);
}
catch {
throw new CommandExecutionError(`Could not attach topic "${topic}": failed to type inline topic query`);
}
await page.wait({ time: 1.2 }); // Let the suggestion dropdown render.
// The suggestion dropdown lives inside the editor's closed shadow root,
// so light-DOM queries cannot enumerate its items. XHS auto-highlights
// the first matching suggestion as soon as the query is typed, so
// pressing Enter accepts it directly. `page.nativeClick` would also
// work but is not always wired up in the browser-bridge wrapper.
if (typeof page.pressKey !== 'function') {
throw new CommandExecutionError(`Could not attach topic "${topic}": page.pressKey is unavailable`);
}
try {
await page.pressKey('Enter');View on GitHub (pinned to 49907e53dc)
Solutions
- Upgrade the CLI / browser bridge so page.insertText is implemented (CDP Input.insertText).
- Use the supported bundled browser wrapper instead of a custom page object.
- Remove topics from the publish call if your environment cannot support them.
- Check wrapper feature detection before publishing: typeof page.insertText === 'function'.
Example fix
// before
const page = myCustomWrapper.connect();
await xhs.publish({ topics: ['travel'], ... }); // wrapper lacks insertText
// after
const page = require('opencli').browser.connect(); // supported wrapper with CDP insertText
await xhs.publish({ topics: ['travel'], ... }); Defensive patterns
Strategy: type-guard
Validate before calling
// feature-detect the bridge before publishing with topics
if (opts.topics && typeof page.insertText !== 'function') {
console.warn('bridge lacks insertText; dropping topics');
delete opts.topics;
} Type guard
function supportsInlineTyping(page) {
return typeof page.insertText === 'function';
} Try / catch
try {
await xhs.publish(opts);
} catch (err) {
if (err.message.includes('page.insertText is unavailable')) {
console.error('Upgrade the browser bridge to a CDP-capable version');
} else throw err;
} Prevention
- Use the officially supported browser wrapper
- Keep the CLI and bridge updated
- Feature-detect page.insertText before topic publishes
- Drop topics gracefully in environments without CDP
When it happens
Trigger: Using an older or alternative browser automation bridge whose page object does not expose insertText; a downgraded/patched wrapper (e.g. custom page shim) lacking CDP text insertion; wrong driver version.
Common situations: Mixing this CLI with a custom Puppeteer/Playwright-style page object; older opencli browser bridge versions; running in environments where CDP insertText is stubbed out.
Related errors
- Could not attach topic "${topic}": failed to type inline top
- Could not attach topic "${topic}": page.pressKey is unavaila
- Current status=${latestActivity?.Status ?? ''}, approvalPend
- No Trae CN response was visible before the timeout. The agen
- Xiaohongshu 点点 did not accept the query. Check login status
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/b4413a09085476c3.
Report an issue: GitHub.