feat(xiaohongshu): use CDP DOM.setFileInputFiles for image upload#574
Merged
jackwener merged 3 commits intojackwener:mainfrom Mar 29, 2026
Merged
Conversation
Replace base64 DataTransfer injection with CDP DOM.setFileInputFiles, which lets Chrome read image files directly from the local filesystem. This eliminates payload size limits that caused "fetch failed" errors when uploading large images (>500KB) through the browser bridge. Changes: - Add 'set-file-input' action to protocol, extension handler, and CDP executor - Add Page.setFileInput() method for CLI-side usage - Rewrite publish image upload to use CDP path, with base64 fallback for older extension versions that don't support the new action - Add clear warning when falling back to base64 with large payloads Closes jackwener#542 (partially — image upload reliability) Co-Authored-By: Claude Opus 4.6 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DOM.setFileInputFilesfor image upload inxiaohongshu publishProblem
When publishing with images larger than ~500KB, the base64-encoded payload sent through
page.evaluate()→sendCommand('exec')exceeds the browser bridge message channel limits, causing a crypticTypeError: fetch failedwith no useful error context. Users have no idea the issue is image size.Solution
Use CDP
DOM.setFileInputFiles(the same mechanism Playwright/Puppeteer use internally) to set file paths directly on the<input type="file">element. Chrome reads the files from disk — zero base64 overhead.Files changed:
extension/src/protocol.ts— addset-file-inputaction typeextension/src/cdp.ts— addsetFileInputFiles()usingDOM.getDocument→DOM.querySelector→DOM.setFileInputFilesextension/src/background.ts— addhandleSetFileInputdispatchersrc/browser/daemon-client.ts— extendDaemonCommandwithfilesandselectorfieldssrc/browser/page.ts— addPage.setFileInput()methodsrc/types.ts— add optionalsetFileInputtoIPageinterfacesrc/clis/xiaohongshu/publish.ts— rewriteuploadImages()with CDP primary + base64 fallbackBackward compatibility
setFileInputis optional onIPage— no breaking change for other adaptersTest plan
npx tsc --noEmitpasses)🤖 Generated with Claude Code