chatbox icon indicating copy to clipboard operation
chatbox copied to clipboard

[BUG] Clipboard broken on Linux/Wayland - pasting text selected from Chatbox crashes or hangs receiving applications

Open littleme02 opened this issue 9 months ago • 0 comments

On Linux with Wayland compositors (tested on Hyprland), selecting text in Chatbox and copying it (Ctrl+C or right-click copy) then pasting into other applications causes those applications to hang or crash.

Note: the explicit copy buttons on messages and code blocks work fine - this only affects native text selection copy.

Steps to Reproduce

  1. Open Chatbox on Linux with a Wayland compositor
  2. Start a chat and get a response with some text
  3. Select some text in the response with your mouse
  4. Press Ctrl+C to copy
  5. Switch to another application (e.g. a text editor, terminal)
  6. Press Ctrl+V to paste
  7. The receiving application hangs or crashes

Probable Root Cause

Chatbox runs as an XWayland application. In XWayland, the clipboard is "live" - the source application (Chatbox/Electron) must keep serving clipboard requests from other apps for as long as the data is on the clipboard. When Wayland-native apps request the clipboard content, they communicate through the XWayland clipboard bridge to Electron. This is slow and unreliable, causing receiving apps to time out and crash.

Fix Intercept the document copy event in the renderer and use wl-copy to hand the clipboard data off to the Wayland compositor's clipboard daemon immediately. This makes the data available system-wide without Electron needing to serve it.

// renderer: intercept copy events document.addEventListener('copy', (e) => { const selectedText = window.getSelection()?.toString() if (selectedText) { e.preventDefault() electronAPI.invoke('clipboard-write', selectedText) } }, true)

// main process: write via wl-copy ipcMain.handle('clipboard-write', (_event, text: string) => { if (process.platform === 'linux') { const proc = spawn('wl-copy', [], { stdio: ['pipe', 'ignore', 'ignore'] }) proc.stdin.write(text) proc.stdin.end() } })

Environment

  • OS: Arch Linux
  • Desktop: Hyprland (Wayland)
  • Chatbox version: 1.19.0

littleme02 avatar Feb 17 '26 19:02 littleme02