Skip to content

rx.set_clipboard from a backend event handler fails on Safari/iOS with NotAllowedErrorΒ #6583

@carlosabadia

Description

@carlosabadia

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions