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

オープン
#6,583 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

  • #6595 @carlosabadia による — マージされずにクローズ

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
52/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
javascript, python
領域
frontend, web-dev

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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)
主要言語
Python
スター
29k
フォーク
1.8k
平均マージ
3日 5時間
マージ済み PR(30日)
182

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

reflex-dev/reflex のほかの issue

reflex-dev/reflex の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。