Skip to content

Instantly share code, notes, and snippets.

@OliDM
Created August 12, 2013 00:03
Show Gist options
  • Save OliDM/6207458 to your computer and use it in GitHub Desktop.
Save OliDM/6207458 to your computer and use it in GitHub Desktop.
// Print out data URLs for all images / canvases on the page.
// dataurl.js
// https://github.com/bgrins/devtools-snippets
// Print out data URLs for all images / canvases on the page.
(function() {
console.group("Data URLs");
[].forEach.call(document.querySelectorAll("img"), function(i) {
var c = document.createElement("canvas");
var ctx = c.getContext("2d");
c.width = i.width;
c.height = i.height;
try {
ctx.drawImage(i, 0, 0);
console.log(i, c.toDataURL());
}
catch(e) {
console.log(i, "No Permission - try opening this image in a new tab and running the snippet again?", i.src);
}
});
[].forEach.call(document.querySelectorAll("canvas"), function(c) {
try {
console.log(c, c.toDataURL());
}
catch(e) {
console.log(c, "No Permission");
}
});
console.groupEnd("Data URLs");
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment