Clipboard: HTTP-safe fallback for copy actions#98
Merged
Conversation
navigator.clipboard is undefined on non-secure (plain HTTP) origins, so copy actions in db-console (Copy as Markdown/JSON), ResourceBrowser, ViewDefinition, claude-chat and notebooks threw "Cannot read properties of undefined (reading 'writeText')". Add a shared utils/clipboard.ts helper that prefers navigator.clipboard and falls back to a Range-based selection plus a capture-phase "copy" listener with stopImmediatePropagation. That sidesteps both Radix DropdownMenu's FocusScope and CodeMirror's own copy handler, which were making the fallback copy whatever was selected in the SQL editor. Replace all direct navigator.clipboard.writeText callers with the helper.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
navigator.clipboardisundefined, so every Copy action in the UI threwCannot read properties of undefined (reading 'writeText')— reproducible in DB Console → Result → Copy as JSON / Markdown.src/utils/clipboard.tswith acopyToClipboard(text)helper that prefersnavigator.clipboard.writeTextand falls back to aRange/Selection-based path. The fallback installs a capture-phasecopylistener withstopImmediatePropagationso CodeMirror's own copy handler can't overwriteclipboardData(otherwise it was copying whatever line was focused in the SQL editor). Selection viaRangealso avoids Radix DropdownMenu's FocusScope yanking focus back to the trigger.navigator.clipboard.writeTextcallers: db-console result export (3 sites), ResourceBrowser query bar, claude-chat element picker & badge, ViewDefinition materialized-view toast, notebooks share URL.Test plan
navigator.clipboardpath.