I'm trying to create a plugin, that uses chrome.tabs.getSelected
to find current URL,
Below I attached a minimal example, when any key is pressed, a dialog will popup, but it kept telling me chrome.tabs.getSelected
is undefined:
Manifest file:
{ "content_scripts": [ { "matches": ["http://*/*" , "https://*/*"], "js" : [ "main.js" ] } ], "manifest_version": 2, "description": "XX", "icons": { "128": "icon.png", "16": "button.png", "32": "button.png", "48": "icon.png" }, "name": "XX", "permissions": [ "tabs", "http://*/*", "https://*/*" ], "version": "1.2" }
And main.js:
window.addEventListener("keyup", function(e) { chrome.tabs.getSelected(null, function(tab) { // undefined alert (tab.url); }); } , false);
Chromium version: Version 21.0.1180.89 (154005)
EDIT
window.addEventListener("keyup", function(e) { chrome.tabs.query( {active:true}, function(tab) { alert (tab.url); }); } , false);
I really don't get it now, tabs.query doesn't work either.
