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

Abierto
#6,583 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

  • #6595 de @carlosabadia — cerrado sin fusionar

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
52/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Tranquilo
Stack tecnológico
javascript, python
Área
frontend, web-dev

Línea de trabajo

Start with rx.set_clipboard and the backend @rx.event handling shown in the minimal reproduction, then reproduce the failure in Safari and iOS Safari. Trace where the clipboard write runs after the WebSocket round-trip; done means the same example copies successfully during the originating user gesture without breaking Chromium or Firefox.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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)
Lenguaje dominante
Python
Estrellas
29k
Forks
1.8k
Merge medio
3 d 5 h
PR fusionados (30 d)
182

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de reflex-dev/reflex

Todos los issues de reflex-dev/reflex

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.