[BUG] chat.deepseek.com: Code block copy button fails with execCommand error; manual selection escapes block when overflow is active
Describe the bug
Two related defects in the code block component of the web chat interface at chat.deepseek.com:
- The "Copy" button in the code block banner does not copy anything and logs a
document.execCommandwarning to the console. - Manual selection of code inside a code block escapes the block and selects the entire page when the block's content overflows.
To Reproduce
Bug 1:
- Open a chat on
chat.deepseek.comwith a code block. - Click the "Copy" button in the code block banner.
- Open DevTools (
F12) → Console tab.
Bug 2:
- Open a chat on
chat.deepseek.comwith a code block containing enough content to cause overflow (long lines or many lines). - Start selecting the code from the left padding area of the block (the empty space between the left border and the first character).
- Drag the mouse to the right or left.
Expected behavior
Bug 1: The code should be copied to the clipboard without errors.
Bug 2: Selection should remain constrained to the code block, regardless of whether the drag starts in the padding area.
Screenshots
Not included. The console warning (Bug 1) is text-based and quoted below; Bug 2 is behavioral and best verified by attempting a manual selection.
Additional context
Bug 1: "Copy" button fails with document.execCommand warning
Actual behavior — the following warning appears in the console:
document.execCommand('cut'/'copy') was denied because it was not called from inside a short running user-generated event handler.The code is not copied to the clipboard.
Suspected root cause: the page appears to use document.execCommand('copy') as a fallback inside an asynchronous handler (e.g., after navigator.clipboard.writeText() throws). Modern browsers block execCommand('copy') when it is not called synchronously within a user gesture — this is standard security behavior, not a Firefox-specific issue.
Suggested fix: remove the asynchronous fallback and rely solely on navigator.clipboard.writeText(), which returns a Promise and works correctly with async code.
Bug 2: Manual selection escapes the block when overflow is active
The bug manifests only when overflow is active in the code block — that is, when content exceeds the block's dimensions and a scrollbar appears (either horizontal or vertical). When the code is short enough not to cause overflow, selection works correctly.
Actual behavior: when the selection starts in the padding area, the selection root is escalated above the <pre> element. Dragging the mouse then selects the entire page (or the entire message block) instead of just the code. When the cursor passes over whitespace text nodes between <span> elements inside the code, the same escalation occurs temporarily.
Root cause: the <pre> element has overflow: auto applied via .ds-markdown pre. This turns <pre> into a scroll container. When the selection anchor is resolved in the padding area (where there is no text), the browser cannot find a valid text position inside the scroll container and escalates the selection root to the nearest non-clipping ancestor. Without overflow: auto, the anchor is correctly resolved to the beginning of the first text line inside <pre>.
Evidence:
- Disabling
overflow: autoon<pre>in DevTools eliminates the problem entirely. - Relevant CSS:
.md-code-block > pre {
padding: 16px;
margin: 0 !important;
white-space: pre-wrap;
word-break: break-all;
}
.ds-markdown pre {
overflow: auto;
margin: 16px 0;
}Additional observation (not a reproduction step): if the code was previously selected in full, the bug tends to manifest more frequently. This may be a browser-specific behavior, and I cannot claim it is a reliable reproduction method — providing it as an observation only.
Suggested fix: move overflow: auto from <pre> to the parent container (.md-code-block or an inner wrapper). This preserves horizontal scrolling for long lines while keeping <pre> as a normal block element, so selection anchors resolve correctly.
Optional suggestion: setting to disable internal scroll in code blocks
This suggestion is not directly related to the bugs described above and is not part of the request to fix them. Whether to implement it is entirely at the developers' discretion.
Some users (myself included) prefer the page to scroll as a whole rather than having nested scroll containers inside code blocks. Nested scrollbars can also cause the browser to scroll the code block instead of the page when the mouse wheel is used over it.
I propose adding a user setting (e.g., in interface settings) to disable internal scrolling in code blocks. When disabled, long lines would rely on the existing white-space: pre-wrap behavior and wrap naturally. This setting exists in some other AI chat interfaces, so there is precedent for it being a useful option.
Environment
- Product:
chat.deepseek.com(web interface) - Browser: Firefox 128.3.1esr (64-bit)
- OS: Linux, X11
Note: The manual selection issue is not browser-specific; it stems from the interaction between overflow: auto on <pre> and the browser's selection anchor resolution algorithm. The execCommand warning is also browser-agnostic and is the browser correctly enforcing the user-gesture requirement for clipboard writes.
Thank you for your attention to these issues. The DeepSeek web interface is otherwise the highest-quality AI chat UI I have used.
Source: deepseek-ai/DeepSeek-V3