Last active
October 10, 2024 18:35
-
-
Save refparo/0f2c84587b86f09d98fbb61c8d07b40a to your computer and use it in GitHub Desktop.
Copy canvas to clipboard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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