Google Chrome Extension Tab URL - How do I make it global?

I am using the following code:

var myUrl;
chrome.tabs.getSelected(null, function(tab) {
    myURL = tab.url;    
 console.log('my url is ' + myUrl);

And in the console I get:

my url is undefined

I want the value of myURL to be the user's current url, but I am not sure what I am doing wrong here. I have tried different variations, including a return, but that had not worked.


Much like Skalar Wag said, the timing seems to be my problem.

I wanted to test that the variable was passed, because I was using in other segments of the code. I have resolved this concern and my application worked out great, thanks!

Need Your Help

Viewing jasper reports on client side in vaadin application

java applet jasper-reports vaadin

I am working on a vaadin application in which I have to use JasperReports. Now what I want is to whenever a report is generated, it should be viewed in JasperViewer. But problem is that the JasperV...

How to access constant string in runtime using a string which holding its name?

objective-c runtime

I have some constant strings defined in my @implementation file like: