Skip to content

Instantly share code, notes, and snippets.

@refparo
Last active October 10, 2024 18:35
Show Gist options
  • Save refparo/0f2c84587b86f09d98fbb61c8d07b40a to your computer and use it in GitHub Desktop.
Save refparo/0f2c84587b86f09d98fbb61c8d07b40a to your computer and use it in GitHub Desktop.
Copy canvas to clipboard
// 1. Save this to a bookmarklet with https://make-bookmarklets.com/
// 2. Run bookmarklet
// 3. Find the canvas in developer tool and "use it in console"
// 4. Run `copyCanvas(temp0)`
// 5. Click anywhere on the webpage (to workaround the restriction that
// clipboard writes must be triggered some user interaction)
window.copyCanvas = canvas => (
canvas.toBlob(blob => (
window.addEventListener("click", () => (
navigator.clipboard.write([
new ClipboardItem({
[blob.type]: blob
})
]).then(() => console.log("Copied!"))
), { once: true })
))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment