5

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?

user2428118
  • 7,935
  • 4
  • 45
  • 72
r.bhardwaj
  • 1,603
  • 6
  • 28
  • 54
  • The error you're getting means that the function `query` doesn't exist on the `chrome.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 Jun 13 '12 at 08: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 Jun 13 '12 at 08:32

2 Answers2

2

Actually 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.

Community
  • 1
  • 1
r.bhardwaj
  • 1,603
  • 6
  • 28
  • 54
1

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;
Tom
  • 770
  • 9
  • 18
  • 1
    thanks...tab[0] works but i want to ask in the given query active:true what the other tab array contains means what value does tab[1],tab[2]... will hold ?? – r.bhardwaj Jun 13 '12 at 09:11