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>
source share