在firefox扩展中仅使用js拍摄屏幕截图

von*_*dip 3 javascript firefox-addon

我正在考虑构建一个firefox扩展.此扩展需要执行屏幕截图的能力.是否有可能只使用javascript这样做?

Jua*_*des 6

更新:此功能已从Firefox中删除,除非您正在编写插件.请查看不同的替代方案,请参阅http://badassjs.com/post/12473322192/hack-of-the-day-rendering-html-to-a-canvashttps://developer.mozilla.org/en-US /文档/网络/ API/CanvasRenderingContext2D/drawWindow

回到过去,你可以:拿一个firefox窗口的截图,是的,这很容易受到伤害.你必须将它渲染到画布中.请参阅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>
Run Code Online (Sandbox Code Playgroud)

如果你的意思是整个桌面的截图,我不这么认为

  • 我不确定你的意思,这在HTML5被称为HTML5之前就已存在.这只是我提到的firefox画布支持的 (2认同)
  • 嗯...在Firefox 39的Web控制台中尝试这个,而``ctx.drawWindow`似乎不存在,但``ctx.drawImage`确实存在 - 但它有不同的语法?! (2认同)