Skip to content

Allow rx.set_clipboard to fetch from a URL (Safari-safe) #6404

@Alek99

Description

@Alek99

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestA feature you wanted added to reflex

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions