Taking screenshot using javascript for chrome extensions

前端 未结 5 2040
名媛妹妹
名媛妹妹 2020-11-27 10:47

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

5条回答
  •  孤城傲影
    2020-11-27 11:19

    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!

提交回复
热议问题