xiaohongshu: publish --images always fails (fileChooserOpened never fires) + draft-delete exits 0 on dry run
Two bugs found while building an automated publish pipeline
Both reproduced on opencli 1.8.8 (latest release, verified via releases/latest) with the xiaohongshu adapter.
Bug 1: xiaohongshu publish --images always fails — fileChooserOpened is never fired
Steps
opencli xiaohongshu publish "body text" \
--title "a title" \
--images /abs/path/1.jpg,/abs/path/2.jpg,/abs/path/3.jpg \
--draft trueActual
Image injection failed: Page.fileChooserOpened not received within 5s
— the input may not have opened a file chooser.
Debug screenshot: /tmp/xhs_publish_upload_debug.png
exitCode: 1Expected Images are injected, the note is saved as a draft with 3 images.
Analysis
uploadImages() in clis/xiaohongshu/publish.js tries the CDP path first:
if (page.setFileInput) {
...
await page.setFileInput(absPaths, selector);
return { ok: true, count: absPaths.length };
}
catch (err) {
const msg = err instanceof Error ? err.message : String(err);
if (msg.includes('Unknown action') || msg.includes('not supported') || msg.includes('Not allowed')) {
// fall through to legacy
}
else {
return { ok: false, count: 0, error: msg }; // <-- dies here
}
}Two problems compound:
Page.fileChooserOpenedis not the right signal forDOM.setFileInputFiles. That CDP command sets files on an input element directly and does not open a native file chooser, so the event the bridge waits for is not guaranteed to fire. The 5s wait then always expires.- The existing legacy base64
DataTransferfallback is unreachable, because the thrown message (fileChooserOpened ... within 5s) is not in the allow-list, so the function returns early instead of falling through.
Workaround that makes it work
Adding the two message fragments to the allow-list lets it reach the already-present legacy DataTransfer injection, and publishing succeeds with 3 images:
if (msg.includes('Unknown action') || msg.includes('not supported') || msg.includes('Not allowed')
|| msg.includes('fileChooserOpened') // CDP path waits for an event it never gets
|| msg.includes('within 5s')) {
// fall through to legacy base64
}Suggested fix
Either make the setFileInput action treat a missing fileChooserOpened as a signal to fall through to the legacy path (rather than a hard failure), or have set-file-input resolve on the CDP call itself instead of waiting on a browser event. Searching existing issues for fileChooser returns 0 results, so this looks unreported.
Bug 2: draft-delete exits 0 on a dry run
Steps
opencli xiaohongshu draft-delete s:bee21095-768e-4a5d-afb2-9c385d1ef738Actual
- status: dry-run
id: s:bee21095-...
message: Draft exists. Re-run with --execute to delete.exit code: 0, and the draft is still in drafts.
Expected
A no-op dry run should be distinguishable from a completed action by exit code (e.g. non-zero, or a documented status: dry-run code), so scripted callers cannot mistake "nothing happened" for success. As it stands, a loop that checks only the exit code reports success while every draft is still there.
Note: the dry-run-by-default design itself is good and worth keeping — only the exit-code signalling is the problem.
Environment
- opencli 1.8.8
- macOS (arm64)
- xiaohongshu adapter, authenticated session
Source: jackwener/OpenCLI