Skip to content Skip to sidebar Skip to footer

Get Current Page Url In Chrome Extension

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

Solution 1:

Actually the error

UncaughtTypeError: Cannot call method 'query'ofundefined

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.

Solution 2:

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;

Post a Comment for "Get Current Page Url In Chrome Extension"