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

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

问题描述

我搜索了很多关于使用 JS 拍照的搜索,但似乎没有一个有用.有人说使用activeX控件,这不适合我的情况.我希望用JS拍照并上传到服务器.

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.

推荐答案

由于您在 Chrome 扩展程序中使用它,Tab API 有一个名为 captureVisibleTab 的方法,它允许捕获指定窗口中当前选定选项卡的可见区域.

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.
});

您可以通过添加 {quality: 50} 来控制属性并更改格式,所有这些都在上述文档中进行了描述.

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

HTML5 之美,您可以使用 HTML5 Canvas 更改该图像,您可以非常轻松地操作、转换、修改、剪辑任何您想要的东西!

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天全站免登陆