diff --git a/content/en/snippets/others/reading_clipboard.md b/content/en/snippets/others/reading_clipboard.md deleted file mode 100644 index 030b402..0000000 --- a/content/en/snippets/others/reading_clipboard.md +++ /dev/null @@ -1,48 +0,0 @@ ---- -title: "Reading clipboard value" -weight: 10 -ie_support: true ---- - -Use this snippet when you want to read the value of clipboard if it is copied by `document.execCommand("copy")` in the previous steps. - -Note: This snippet assumes the copied data is text. - -### Usage - -You need a pair of JS Steps in your scenario: - -1. Adding an event listener for `copy` event which stores the data to `localStorage` -2. Getting the data from `localStorage` - -The step 1 should be inserted **before the click step**, then you can read the data after the click step. - -```js -// Step 1 -document.addEventListener("copy", function (event) { - var active = document.activeElement; - if ( - active instanceof HTMLInputElement || - active instanceof HTMLTextAreaElement - ) { - var data = active.value.substring( - active.selectionStart, - active.selectionEnd - ); - localStorage.setItem("clipboard", data); - } -}); - -// Step 2 -return localStorage.getItem("clipboard"); -``` - -### Caveat - -#### iOS Safari doesn't work with `document.execCommand("copy")` with Autify - -Due to technical limitation, Autify can't properly trigger `document.execCommand("copy")` only on iOS Safari environment yet. Therefore, this snippet (or any other workaround) won't work with iOS Safari as of March 2022. - -#### Doesn't support `navigation.clipboard.writeText()` API - -If your website uses `navigation.clipboard.writeText()` API to copy the value to clipboard, this approach doesn't work because it supposed to send `clipboardchange` event but Chromium hasn't implemented the event yet as of March 2022. diff --git a/content/ja/snippets/others/reading_clipboard.md b/content/ja/snippets/others/reading_clipboard.md deleted file mode 100644 index 190644c..0000000 --- a/content/ja/snippets/others/reading_clipboard.md +++ /dev/null @@ -1,48 +0,0 @@ ---- -title: "クリップボードの値を読み出す" -weight: 10 -ie_support: true ---- - -このスニペットを使うと、前のステップで`document.execCommand("copy")`を使ってクリップボードにコピーされた値を読みだすことができます。 - -注: このスニペットはコピーされたデータがテキストであると仮定しています。 - -### 利用方法 - -2 つのペアになった JS ステップをシナリオに追加する必要があります。 - -1. データを`localStorage`に保存するリスナーを、`copy`イベントのイベントリスナーに追加するステップ -2. `localStorage`からデータを読み出すステップ - -ステップ 1 は**クリックするステップの前に**挿入する必要があります。そうすることで、クリックするステップの後でデータを読み出すことができるようになります。 - -```js -// Step 1 -document.addEventListener("copy", function (event) { - var active = document.activeElement; - if ( - active instanceof HTMLInputElement || - active instanceof HTMLTextAreaElement - ) { - var data = active.value.substring( - active.selectionStart, - active.selectionEnd - ); - localStorage.setItem("clipboard", data); - } -}); - -// Step 2 -return localStorage.getItem("clipboard"); -``` - -### 注意点 - -#### Autify では iOS Safari の`document.execCommand("copy")` は機能しません - -技術的制約により、Autify では`document.execCommand("copy")` が iOS Safari の環境上でのみうまく発動しません。そのため、このスニペット(および他の回避策)は iOS Safari 上では機能しません。(2022 年 3 月現在) - -#### `navigation.clipboard.writeText()` API では使えません - -もしサイトが`navigation.clipboard.writeText()` API を使ってクリップボードにコピーしている場合、このアプローチはうまく動きません。この API は`clipboardchange`というイベントを発行することになっているのですが、2022 年 3 月現在 Chromium ではこのイベントがまだ実装されていません。