Describe the Feature
rx.set_clipboard(content) today is a thin wrapper around navigator.clipboard.writeText(content) — it expects the content to already be in hand. There is no first-class way to say "copy the contents of this URL to the clipboard" without dropping into raw JS.
The naive userland version (on_click=run_script(\"fetch(url).then(t => navigator.clipboard.writeText(t))\")) works in Chromium but fails silently in Safari, because by the time the fetch resolves, the user-gesture window has closed and the clipboard write is rejected.
The Safari-safe pattern is to call navigator.clipboard.write([new ClipboardItem({ 'text/plain': fetch(url).then(...) })]) — write is invoked synchronously inside the click handler with a Promise-backed ClipboardItem, which preserves the gesture binding while still letting the fetch happen async.
It would be nice if Reflex provided this as a primitive so apps don't have to ship that JS themselves.
Proposed API
# Option A: extend set_clipboard
rx.set_clipboard(url=\"/some/file.md\")
# Option B: a sibling helper, clearer about the fetch
rx.set_clipboard_from_url(\"/some/file.md\")
Either should compile to the ClipboardItem-with-Promise pattern under the hood.
Use cases
- Docs sites with a "copy page as Markdown" button (the original motivation — currently working around this with
run_script in docs/app/reflex_docs/templates/docpage/docpage.py).
- "Copy share link" buttons that resolve a server-generated URL.
- Any "copy contents of X" UX where X is fetched, not pre-loaded.
Additional context
Describe the Feature
rx.set_clipboard(content)today is a thin wrapper aroundnavigator.clipboard.writeText(content)— it expects the content to already be in hand. There is no first-class way to say "copy the contents of this URL to the clipboard" without dropping into raw JS.The naive userland version (
on_click=run_script(\"fetch(url).then(t => navigator.clipboard.writeText(t))\")) works in Chromium but fails silently in Safari, because by the time the fetch resolves, the user-gesture window has closed and the clipboard write is rejected.The Safari-safe pattern is to call
navigator.clipboard.write([new ClipboardItem({ 'text/plain': fetch(url).then(...) })])—writeis invoked synchronously inside the click handler with a Promise-backedClipboardItem, which preserves the gesture binding while still letting the fetch happen async.It would be nice if Reflex provided this as a primitive so apps don't have to ship that JS themselves.
Proposed API
Either should compile to the
ClipboardItem-with-Promise pattern under the hood.Use cases
run_scriptindocs/app/reflex_docs/templates/docpage/docpage.py).Additional context
ClipboardItemwith a Promise data field: Safari 13.1+, Chrome 76+, Firefox 127+. Safe to use as the primary path with the existingwriteTextflow as fallback.