openclaw - 💡(How to fix) Fix [Bug] WebChat 图片粘贴功能不工作 [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#54351Fetched 2026-04-08 01:28:36
View on GitHub
Comments
1
Participants
2
Timeline
2
Reactions
0
Author
Participants
Timeline (top)
commented ×1cross-referenced ×1

Code Example

# 没有任何请求记录
# 只有 WebSocket 连接和心跳

---

[DingTalk] 收到消息: type=picture images=1
[DingTalk][Image] 开始下载图片: http://...
[DingTalk][Image] 图片下载成功: path=.../media/inbound/xxx.png

---

// 粘贴事件处理
function _p(e, t) {
  let n = e.clipboardData?.items;
  if (!n || !t.onAttachmentsChange) return;
  
  let r = [];
  for (let e = 0; e < n.length; e++) {
    let t = n[e];
    t.type.startsWith(`image/`) && r.push(t)
  }
  // ... 读取为 base64 并调用 onAttachmentsChange
}

---

Np({
  attachments: e.chatAttachments,
  onAttachmentsChange: t => e.chatAttachments = t,
  // ...
})

---

Web UI: improve WebChat image paste previews and allow image-only sends. (#1925)
Web UI: add `img` to DOMPurify allowed tags so markdown images render in webchat. (#15437)
RAW_BUFFERClick to expand / collapse

问题描述

WebChat 的图片粘贴功能声明已支持(CHANGELOG #1925),但实际测试中完全不工作。粘贴图片后没有任何请求发送到后端。

复现步骤

  1. 启动 OpenClaw Gateway:openclaw gateway
  2. 打开浏览器访问 http://127.0.0.1:18789/
  3. 在聊天输入框粘贴一张图片(Ctrl/Cmd + V 或拖拽)
  4. 图片无法发送,输入框无反应

预期行为

  • 粘贴图片后应该显示预览
  • 图片应该上传到 Gateway
  • Agent 应该收到图片并能够处理

实际行为

  • 粘贴图片后没有任何反应
  • 没有 HTTP 请求发出
  • Gateway 日志中没有任何图片上传记录

环境

项目
OpenClaw 版本2026.3.23-2
操作系统macOS arm64
Node 版本v24.8.0
WebChat 客户端版本v2026.3.23-2

日志分析

粘贴图片时 Gateway 日志:

# 没有任何请求记录
# 只有 WebSocket 连接和心跳

对比:钉钉渠道图片发送成功时的日志:

[DingTalk] 收到消息: type=picture images=1
[DingTalk][Image] 开始下载图片: http://...
[DingTalk][Image] 图片下载成功: path=.../media/inbound/xxx.png

代码分析

前端代码已实现完整的图片粘贴逻辑:

// 粘贴事件处理
function _p(e, t) {
  let n = e.clipboardData?.items;
  if (!n || !t.onAttachmentsChange) return;
  
  let r = [];
  for (let e = 0; e < n.length; e++) {
    let t = n[e];
    t.type.startsWith(`image/`) && r.push(t)
  }
  // ... 读取为 base64 并调用 onAttachmentsChange
}

组件也正确传递了回调:

Np({
  attachments: e.chatAttachments,
  onAttachmentsChange: t => e.chatAttachments = t,
  // ...
})

相关 CHANGELOG

Web UI: improve WebChat image paste previews and allow image-only sends. (#1925)
Web UI: add `img` to DOMPurify allowed tags so markdown images render in webchat. (#15437)

排查结论

  1. 不是配置问题 — 没有相关配置项需要开启
  2. 不是版本问题 — 已更新到最新版本
  3. 前端代码存在 — 但运行时不工作

可能原因

  1. 粘贴事件被其他处理器拦截
  2. clipboardData.items 在某些情况下为空
  3. 状态管理问题导致 onAttachmentsChange 未被调用

临时解决方案

  • 使用钉钉等支持图片的渠道发送图片
  • 或将图片保存到本地,告知 Agent 图片路径

extent analysis

Fix Plan

To resolve the issue of images not being sent when pasted into the WebChat input field, we need to address the potential causes identified:

  • Ensure the paste event is not being intercepted by other handlers.
  • Verify that clipboardData.items is not empty when pasting images.
  • Confirm that the state management is correctly calling onAttachmentsChange.

Here are the steps to fix the issue:

  1. Check for Event Interception: Inspect the code for any event listeners that might be intercepting the paste event before it reaches the intended handler. Remove or modify these listeners if necessary.

  2. Verify Clipboard Data: Add debugging logs to check the contents of clipboardData.items when an image is pasted. This will help determine if the issue lies in the data being empty or not.

function _p(e, t) { let n = e.clipboardData?.items; console.log('Clipboard items:', n); // Add this line for debugging // ... rest of the function remains the same }


3.  **State Management and `onAttachmentsChange`**: Ensure that `onAttachmentsChange` is being called correctly by adding a log statement inside this callback.

    ```javascript
Np({
  attachments: e.chatAttachments,
  onAttachmentsChange: t => {
    console.log('onAttachmentsChange called with:', t);
    e.chatAttachments = t;
  },
  // ...
})
  1. Modify the Paste Event Handler: If clipboardData.items is empty, consider using a different approach to access the pasted image data, such as using the paste event on the document or input element directly.

document.addEventListener('paste', (e) => { if (e.clipboardData) { const items = e.clipboardData.items; // Process the items here } });


### Verification
To verify that the fix worked:

*   Paste an image into the WebChat input field.
*   Check the browser console for the debugging logs added in the steps above to ensure that `clipboardData.items` is not empty and `onAttachmentsChange` is being called.
*   Verify that the image is correctly uploaded and displayed in the chat.

### Extra Tips
*   Ensure that the browser supports the `clipboardData` API and that there are no security restrictions preventing access to the clipboard data.
*   Consider adding error handling for cases where the image paste fails due to browser restrictions or other issues.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING