Describe the bug
On Safari (desktop) and iOS Safari, rx.set_clipboard(...) fails with
NotAllowedError: The request is not allowed by the user agent or the platform in the current context whenever it is returned from a backend
@rx.event handler (or otherwise reached after a WebSocket round-trip).
The same code works on Chromium and Firefox.
Root cause
Safari/WebKit requires navigator.clipboard.writeText() to be invoked
synchronously inside the user-activation window of the originating user
gesture (click/keydown). When rx.set_clipboard is returned from a backend
event handler, the actual writeText call runs from the socket.io message
handler, after the round-trip β so user activation is no longer in
effect and WebKit rejects the write.
Minimal repro
import reflex as rx
class State(rx.State):
secret: str = "hello"
@rx.event
def copy(self):
return rx.set_clipboard(self.secret)
def index():
return rx.button("Copy", on_click=State.copy)
app = rx.App()
app.add_page(index)
Describe the bug
On Safari (desktop) and iOS Safari,
rx.set_clipboard(...)fails withNotAllowedError: The request is not allowed by the user agent or the platform in the current contextwhenever it is returned from a backend@rx.eventhandler (or otherwise reached after a WebSocket round-trip).The same code works on Chromium and Firefox.
Root cause
Safari/WebKit requires
navigator.clipboard.writeText()to be invokedsynchronously inside the user-activation window of the originating user
gesture (click/keydown). When
rx.set_clipboardis returned from a backendevent handler, the actual
writeTextcall runs from the socket.io messagehandler, after the round-trip β so user activation is no longer in
effect and WebKit rejects the write.
Minimal repro