使用javascript为Chrome扩展添加屏幕截图 [英] Taking screenshot using javascript for chrome extensions

查看:178
本文介绍了使用javascript为Chrome扩展添加屏幕截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经做了很多关于使用JS拍摄照片的搜索,但似乎没有用处。有人说使用activeX控件,这不适合我的情况。我希望能够使用JS拍摄照片并将其上传到服务器。 由于您在Chrome扩展程序中使用了此功能, 标签API 有一个名为 captureVisibleTab ,它允许捕获指定窗口中当前选定选项卡的可见区域。



要使用该功能,您只需将选项卡添加到您的权限清单中即可。从背景页面或弹出窗口(或任何其他扩展页面),只需调用该方法即可:

  chrome。 tabs.captureVisibleTab(null,{},function(image){
//您可以添加该图像HTML5画布,或者Element。
});

您可以通过添加{quality:50}来控制属性并更改格式上面提到的文档。

HTML5的美妙之处在于,您可以使用HTML5 Canvas修改图片,您可以非常轻松地操纵,转换,修改,剪辑任何您想要的内容!



希望这就是你要找的!新年快乐!


I have made a lot of search regarding taking pictures using JS but none seem to be useful. Some say using activeX controls, which doesn't suit my situation. I was hoping to take picture using JS and upload it a server.

解决方案

Since you're using this in Chrome Extensions, the Tab API has a method called captureVisibleTab, which allows captures the visible area of the currently selected tab in the specified window.

To use that you just add "tabs" to your permissions manifest. And from your background page, or popup (or any other extension page), you just call that method like this:

chrome.tabs.captureVisibleTab(null, {}, function (image) {
   // You can add that image HTML5 canvas, or Element.
});

You can control the property by adding {quality: 50} and change the format too, all described within the docs mentioned above.

The beauty of HTML5, you can alter that image with HTML5 Canvas, you can manipulate, transform, modify, clip, anything you want, very easily!

Hope that is what your looking for! Happy New Years!

这篇关于使用javascript为Chrome扩展添加屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆