I want to get the current page URL from my default_popup
page like this:
chrome.tabs.query({active:true},function(tab){
url = tab.url;
});
And I have registered this popup.html
page in the manifest.json
file. Yet
I am getting the error message:
Uncaught Type Error: Cannot call method 'query' of undefined
What am I doing wrong?
I want to get the current page URL from my default_popup
page like this:
chrome.tabs.query({active:true},function(tab){
url = tab.url;
});
And I have registered this popup.html
page in the manifest.json
file. Yet
I am getting the error message:
Uncaught Type Error: Cannot call method 'query' of undefined
What am I doing wrong?
Share Improve this question edited Jun 13, 2012 at 9:47 user2428118 8,1244 gold badges46 silver badges73 bronze badges asked Jun 13, 2012 at 7:51 r.bhardwajr.bhardwaj 1,6236 gold badges31 silver badges54 bronze badges 2-
The error you're getting means that the function
query
doesn't exist on thechrome.tabs
object. Does the part of the extension you're calling this function from have the privileges to access this function? And does your extension have the tabs privilege? – user2428118 Commented Jun 13, 2012 at 8:22 - yes i my extension have tabs privilege and i am using above chrome.tabs.query() method inside popup.html page which is registered as default_popup in browser_action: field in manifest.json file. – r.bhardwaj Commented Jun 13, 2012 at 8:32
2 Answers
Reset to default 2Actually the error
Uncaught Type Error: Cannot call method 'query' of undefined
was because i was running popup.html page separately (separate from extension ) means i was explicitly opening popup.html page in browser to find the error but i forgot that popup.html can use chrome api if it is an extension page and my extension was not showing url because i was usinf tab.url instead of tab[0].url so Tom suggested right ans.
The callback parameter should specify a function that looks like this:
function(array of Tab result){...}
Maybe you should write like this
url = tab[0].url;