Answer the question
In order to leave comments, you need to log in
Why do google chrome api methods return undefined?
Hello, I'm interested in developing extensions for chrome. I read the documentation, practiced a little and immediately a problem arose.
function getUrl(tabId) {
chrome.tabs.get(tabId, function(data) {
return data.url ;
}) ;
}
var getUrl = function(tabId) {
var url ;
chrome.tabs.get(tabId, function(data) {
url = data.url ;
}) ;
return url ;
}
Answer the question
In order to leave comments, you need to log in
function(data) - is processed asynchronously and therefore you cannot get a result from it using return
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question