Skip to content

Clipboard: HTTP-safe fallback for copy actions#98

Merged
Panthevm merged 1 commit into
masterfrom
clipboard-http-fallback
Jun 8, 2026
Merged

Clipboard: HTTP-safe fallback for copy actions#98
Panthevm merged 1 commit into
masterfrom
clipboard-http-fallback

Conversation

@Panthevm

@Panthevm Panthevm commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • On non-secure origins (plain HTTP) navigator.clipboard is undefined, so every Copy action in the UI threw Cannot read properties of undefined (reading 'writeText') — reproducible in DB Console → Result → Copy as JSON / Markdown.
  • Add src/utils/clipboard.ts with a copyToClipboard(text) helper that prefers navigator.clipboard.writeText and falls back to a Range/Selection-based path. The fallback installs a capture-phase copy listener with stopImmediatePropagation so CodeMirror's own copy handler can't overwrite clipboardData (otherwise it was copying whatever line was focused in the SQL editor). Selection via Range also avoids Radix DropdownMenu's FocusScope yanking focus back to the trigger.
  • Replace all direct navigator.clipboard.writeText callers: db-console result export (3 sites), ResourceBrowser query bar, claude-chat element picker & badge, ViewDefinition materialized-view toast, notebooks share URL.

Test plan

  • DB Console over HTTP: run a query, Copy as JSON → pasted text equals the JSON, not the focused SQL line.
  • DB Console over HTTP: Copy as Markdown and "Copy all as …" with multiple results.
  • DB Console over HTTPS: same actions still use the native navigator.clipboard path.
  • ResourceBrowser: copy current query URL.
  • ViewDefinition: materialize a view, copy the view name from the toast.
  • Claude chat element picker + badge: copy element context.
  • Notebooks: share notebook URL.

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.
@Panthevm Panthevm merged commit 0c9916e into master Jun 8, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant