I can get the URL of the current tab if I click on my extension. But if the extension is already open (user clicks on link that loads a webpage in the current tab, I don't get the current url.)
Here is the code I am using:
<script>
window.addEventListener("load", windowLoaded, false);
function windowLoaded() {
chrome.tabs.getSelected(null, function(tab) {
document.getElementById('currentLink').innerHTML = tab.url;
});
}
</script>
<div id="currentlink">Url will appear here</div>