3

I am trying to write a simple batch script to take some screenshots of internal webpages on my end and came across the fact that firefox has this ability to render the window to canvas:

var canvas = document.createElement('canvas');
var ctx = canvas.getContext("2d");
ctx.drawWindow(window, 0,0, 100, 200, "rgb(255,255,255)");
console.log(canvas.toDataURL("image/png"));

However, this seems to be reserved only form extensions and throws an Error: The operation is insecure.

I don't need to publish this to anyone else and I'm happy to make some internal adjustment to only my Firefox to avoid creating an extension. Is there some sort of about:config setting (or something else) I can tweak to just let this go through even if it's not in an extension?

crickeys
  • 3,075
  • 3
  • 26
  • 27
  • Why don't you use a different tool. Selenium makes it easy http://stackoverflow.com/questions/3422262/take-a-screenshot-with-selenium-webdriver – epascarello Apr 12 '13 at 01:35
  • I've used http://www.paulhammond.org/webkit2png/ in the past with good results. There's something similar floating around for Moz, too. – Dagg Nabbit Apr 12 '13 at 01:40
  • DaggNabbit: Unfortunately, this will be on windows machines. epascarello: I haven't started with selenium, and though that snippet does look simple enough, I'm wondering if Setting up Selenium and actually getting it going is going to take quite a while to do. – crickeys Apr 12 '13 at 01:43
  • Wait, does Selenium IDE perform screenshots? – crickeys Apr 12 '13 at 01:52

1 Answers1

0

Go to about:config and set devtools.chrome.enabled to true
Restart
Go to the tab you want to take screenshot
Press Shift+F4
Switch environment to Browser
Paste the following snippet

var canvas = gBrowser.contentDocument.createElement('canvas');
var ctx = canvas.getContext("2d");
ctx.drawWindow(window, 0,0, 100, 200, "rgb(255,255,255)");
canvas.toDataURL("image/png");

Place the cursor at the end of the last line
Press Control+L
Mission accomplished!

paa
  • 5,048
  • 1
  • 18
  • 22