Skip to content

Instantly share code, notes, and snippets.

@og24715
Created January 9, 2018 08:05
Show Gist options
  • Save og24715/950733967775537a6a13e419bd6c6e41 to your computer and use it in GitHub Desktop.
Save og24715/950733967775537a6a13e419bd6c6e41 to your computer and use it in GitHub Desktop.
異なるoriginの画像からバイナリを取ろうとして失敗

いきさつ

web上の画像を右クリックでs3にアップロードする拡張機能を作りたかった。 chrome拡張機能でコンテキストメニューを追加できる。 画像を選択するとurlが取れる。 canvas使ってurlからバイナリ取ろうとしてセキュリティーエラー出て詰み。

urlからバイナリ取る方法 Get image data in JavaScript? - Stack Overflow

なぜ

Although you can use images without CORS approval in your canvas, doing so taints the canvas. Once a canvas has been tainted, you can no longer pull data back out of the canvas. For example, you can no longer use the canvas toBlob(), toDataURL(), or getImageData() methods; doing so will throw a security error. CORS enabled image - HTML | MDN

異なるoriginの画像をcanvasに使うことは出来ても、そのcanvasからデータは取り出せなくなったとのこと。

どうするの

わからん🐯🍚

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment