I have the latest Chrome, I'm building an extension.
Consider the following code:
var returnTab = false; // init the variable as false
var createNewTab = function(){
returnTab = false; // make sure we start with this var as false
chrome.tabs.create({url:'http://www.google.com/'}, function(tab){
returnTab = tab; // put the returntab object inside the variable
});
while(returntab===false){ }; // wait for the tab to be created.
return returnTab;
};
c = createNewTab();
All fine and it should work; except it doesn't. The createNewTab() function gets stuck into an infinite loop and the variable returnTab never gets the callback return value. If I do it the way I'm meant to do it, without the wait loop everything works and the callback function executes the way it should.
Why isn't this working?
LE: Looks like the callback function waits for the loop to complete. Does anyone know a way to keep the whole function busy until the callback function fires up?