问题
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?
回答1:
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!
来源:https://stackoverflow.com/questions/15961636/override-firefox-insecure-warnings-with-aboutconfig