fix(deepseek): fix send button detection and file upload#1166
fix(deepseek): fix send button detection and file upload#1166jackwener merged 2 commits intojackwener:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes DeepSeek adapter message sending by correctly identifying and clicking the actual send button in sendMessage() instead of always falling back to an Enter keypress.
Changes:
- Replaces global button scanning with DOM traversal from the textarea to its input container.
- Selects the last enabled non-toggle SVG button in that container and clicks it, preserving Enter fallback if no button is found.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (btns[i].getAttribute('aria-disabled') === 'false' | ||
| && btns[i].querySelectorAll('svg').length > 0) { | ||
| btns[i].click(); | ||
| return { ok: true }; |
There was a problem hiding this comment.
The success return shape is inconsistent: the click path returns { ok: true } while the Enter fallback returns { ok: true, method: 'enter' }. This makes it harder for callers/logging to reliably understand how the message was sent. Consider returning a consistent shape for both paths (e.g., include method: 'click' on the click path).
| return { ok: true }; | |
| return { ok: true, method: 'click' }; |
| // Find the send button inside the textarea's input container. | ||
| // Walk up from the textarea until we reach a parent with buttons. | ||
| var container = box.parentElement; | ||
| while (container && !container.querySelector('div[role="button"]')) { | ||
| container = container.parentElement; | ||
| } | ||
| if (container) { | ||
| var btns = container.querySelectorAll('div[role="button"]:not(.ds-toggle-button)'); | ||
| for (var i = btns.length - 1; i >= 0; i--) { | ||
| if (btns[i].getAttribute('aria-disabled') === 'false' | ||
| && btns[i].querySelectorAll('svg').length > 0) { | ||
| btns[i].click(); | ||
| return { ok: true }; | ||
| } |
There was a problem hiding this comment.
This new DOM-walking/button-selection logic is untested. Since this package already has unit tests for utils.js, add coverage for sendMessage() to validate that it finds the correct enabled SVG button in the textarea container and avoids falling back to the Enter key path.
| var btns = container.querySelectorAll('div[role="button"]:not(.ds-toggle-button)'); | ||
| for (var i = btns.length - 1; i >= 0; i--) { | ||
| if (btns[i].getAttribute('aria-disabled') === 'false' | ||
| && btns[i].querySelectorAll('svg').length > 0) { |
There was a problem hiding this comment.
Minor performance/clarity: btns[i].querySelectorAll('svg').length > 0 allocates a NodeList each iteration just to check existence. Using a single-element query (e.g., querySelector('svg')) avoids that overhead and reads more directly as an existence check.
| && btns[i].querySelectorAll('svg').length > 0) { | |
| && btns[i].querySelector('svg')) { |
3f9f17e to
0e2b9eb
Compare
2b8b1f6 to
b5a13d3
Compare
The previous selector `btn.closest('div')?.querySelector('textarea')`
always returned null because the button itself is a div, so
closest('div') returns the button, which has no textarea inside.
This caused every send to fall through to the Enter key fallback.
Walk up from the textarea to find the input container, then select
the last enabled non-toggle button with an SVG icon (the send
button). Excludes `.ds-toggle-button` elements (DeepThink / Search
toggles) so only the actual send button is clicked.
b5a13d3 to
24606bd
Compare
Description
Three bugs in
sendMessageandsendWithFilethat caused--fileupload to silently fail:1. sendMessage button detection always failed. The selector
btn.closest('div')?.querySelector('textarea')always returned null because the button itself is a<div>, soclosest('div')returns the button, which has no textarea inside. This caused every send to use the Enter key fallback, and when the send button was disabled (during file upload), it would click the attachment button instead.Fix: walk up from the textarea to find the input container, then click only the last non-toggle button (the actual send button).
2. sendWithFile sent the message before the file upload finished. DeepSeek shows the file preview chip immediately (optimistic UI), but the send button stays
aria-disabled="true"until the PoW challenge + server upload completes (~2s). The old code sent the message as soon as the preview appeared, before the upload was done.Fix: after
waitForFilePreview, poll until the send button becomes enabled (up to 15s).3. DataTransfer ownership bug.
inp.files = dt.filestransfers the FileList and emptiesdt.files. The old code then passed the now-emptydt.filesto React's onChange.Fix: pass
inp.filesinstead ofdt.filesto onChange.Fixes #1167
Type of Change
Checklist
Documentation (if adding/modifying an adapter)
N/A
Screenshots / Output
File upload now works:
All commands tested: