I'm working on an extension that requires the current tab url. I am able to access the correct url and alert it to the screen, but it isn't being recognized or able to be used elsewhere.
var currentUrl;
chrome.tabs.query({'currentWindow': true, 'active': true, 'lastFocusedWindow': true}, function (tabs) {
alert(tabs[0].url);
//this alerts correctly, but is the line 121 error in the error message
var currentUrl = tabs[0].url;
//this is undefined and can't be used
});
This is the error message from the popup inspector: Error in response to tabs.query: TypeError: Cannot read property 'url' of undefined at Object.callback (chrome- extension://pokiconaaogmgmencihnokkdk/popup.js:121:23) at HTMLButtonElement. (chrome-extension://pokiconaaogmgmencihnokkdk/popup.js:120:19)
My permissions:
"permissions": [ "tabs", "storage" ],
Any ideas would be helpful, thank you.