-
Notifications
You must be signed in to change notification settings - Fork 669
Description
Problem
The xiaohongshu publish command (and potentially other UI automation commands) fails to trigger React event handlers when using JavaScript dispatchEvent() for clicks. This affects:
- Tab switching —
.creator-tabelements don't respond toel.click() - Publish/Submit buttons — React form submission buttons don't fire
- Draft box interactions — Modal open/close and item selection fail
Root cause
React uses a synthetic event system that listens on the document root, not individual DOM nodes. Standard el.click() and even new MouseEvent('click', ...) dispatched via JS don't always propagate through React's event delegation layer.
Current workaround (partial)
Using full pointer/mouse event sequences helps with some elements:
btn.dispatchEvent(new PointerEvent('pointerdown', opts));
btn.dispatchEvent(new MouseEvent('mousedown', opts));
btn.dispatchEvent(new PointerEvent('pointerup', opts));
btn.dispatchEvent(new MouseEvent('mouseup', opts));
btn.dispatchEvent(new MouseEvent('click', opts));This fixed the tab switching but still doesn't work reliably for submit buttons and modal interactions.
Proposed solution
Add CDP-level Input.dispatchMouseEvent support to the page.click() method. This dispatches events at the browser engine level (not JS), which React treats identically to real user input.
// Instead of JS-level:
el.click();
// Use CDP-level:
await cdp.send('Input.dispatchMouseEvent', {
type: 'mousePressed', x, y, button: 'left', clickCount: 1
});
await cdp.send('Input.dispatchMouseEvent', {
type: 'mouseReleased', x, y, button: 'left', clickCount: 1
});Benefits
- Works with React, Vue, Angular, and all SPA frameworks
- Identical to real user mouse clicks
- Already available in the CDP connection that opencli maintains
Environment
- opencli v1.4.1
- macOS, Chrome with Browser Bridge extension
- Affected site: creator.xiaohongshu.com (React SPA)
Additional context
Other [ui] strategy commands on React/Vue SPAs may have similar issues. A CDP click would be a universal fix.