我正在考虑构建一个 Firefox 扩展。 此扩展需要执行屏幕截图的能力。 是否可以只使用 javascript 这样做?
最佳答案
更新:此功能已从 Firefox 中删除,除非您正在编写插件。请寻找不同的替代方案,请参阅 http://badassjs.com/post/12473322192/hack-of-the-day-rendering-html-to-a-canvas和 https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/drawWindow
过去,您可以:截取 firefox 窗口的屏幕截图,是的,这很容易造成伤害。您必须将其渲染到 Canvas 中。参见 https://developer.mozilla.org/en/drawing_graphics_with_canvas#Rendering_Web_Content_Into_A_Canvas
<canvas id='my-canvas'></canvas>
<script>
var canvas = document.getElementById('my-canvas');
var ctx = canvas.getContext("2d");
// Draw the window at the top left of canvas, width=100, height=200, white background
// drawWindow has been removed :(
ctx.drawWindow(window, 0,0, 100, 200, "rgb(255,255,255)");
// Open another window with the thumbnail as an image
open(canvas.toDataURL("image/png"));
</script>
如果你指的是整个桌面的截图,我不这么认为
关于javascript - 在 firefox 扩展中仅使用 js 截屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4742129/