Clipboard API and events を読みました。 Asynchronous Clipboard APIを使ったサンプルをCodepenで作りました。
Google Chromeだと、全部動きます。
FirefoxだとwriteText
しか動きません。write
はwrite
で書き込むためのClipbordItem
がサポートされていないので、インスタンス化しようとするとReferenceError: ClipboardItem is not defined
エラーが起きます。
Chromeでも、read
やreadText
を初めて実行する時は、次のようなダイアログが出るはずです。
出した許可は chrome://settings/content
から取り消せます。
Codepenを埋め込むと動きません。
See the Pen Try to use Ascncronouse Clipboard API by shigeru.nakajima (@ledsun) on CodePen.
Deprecating Permissions in Cross-Origin Iframes - The Chromium Projects をチラ見した感じでは、Codepenの埋め込みスクリプトはiframeを使っているけど、iframeを使う時はallow属性を使って明示的に許可しないといけないようです。