Google Chrome extension: capture_isibleTab problem

I try to capture the current visible tab, but I get undefined. When you click the extension icon, the following code is executed. When a warning is raised, I see undefined instead of the URL.

chrome.browserAction.onClicked.addListener(function(tab) { chrome.windows.getCurrent(function (win) { chrome.tabs.captureVisibleTab(win.id,{"format":"png"}, function(imgUrl) { alert(imgUrl); }); }); }); 

What should I do to get the URL of the captured image? Can someone please help me with this.

Thanks!

+4
source share
2 answers

I assume that your code is taken from the example provided on the Chrome extension website, and yes, it does not work.

Change the permissions attribute inside manifest.json to this:

 "permissions": [ "tabs" ,"<all_urls>" ] 

Cheers, David

+5
source

I tried your code and it did not return undefined for me. Below is the code.
Manifest.json

 { "name": "Test", "version": "1.0", "background_page": "background.html", "browser_action": { "default_icon": "icon.png" }, "permissions": [ "tabs" ] } 

Background.html

 <html> <head> <script> chrome.browserAction.onClicked.addListener(function(tab) { chrome.windows.getCurrent(function (win) { chrome.tabs.captureVisibleTab(win.id,{"format":"png"}, function(imgUrl) { alert(imgUrl); }); }); }); </script> </head> </html> 
+1
source

Source: https://habr.com/ru/post/1345473/


All Articles