Reputation: 12112
I have the following function in my chrome extension's background.js to get the current tab's url:
function getCurrentUrl() {
chrome.tabs.query({currentWindow: true, active: true}, function(tabs) {
var tab = tabs[0]
var keys = []
for(var key in tab) keys.push(key + '-' + tab[key])
alert(keys.join(', '))
})
}
But, the alert dialog shows me:
active-true, height-456, highlighted-true, id-301, incognito-false, index-6, pinned-false, selected-true, status-complete, width-717, windowId-262
The 'tab' object doesn't seem to have a url property, as suggested by other answers on SO. What am I doing wrong?
Upvotes: 1
Views: 1007
Reputation: 12112
To access the url, add the following to manifest.json:
"permissions": [ "tabs" ]
source: http://developer.chrome.com/extensions/tabs.html
Upvotes: 2