kajacx
kajacx

Reputation: 12939

Chrome extensions: make chrome.tabs.query() synchronous

I am currently using this code:

url = "unknown";
chrome.tabs.query({'active': true, 'lastFocusedWindow': true}, function(tabs) {
    console.log(tabs); //test, prints one-element array as expected
    url = tabs[0].url;
});
$("#url_div").html(url);

to get current URL, but chrome.tabs.query() is asynchronous, how can I make it synchronous? (i.e. add asynch: false somewhere)

I know I could set the URL inside the query, or call another function from there, but best would be (example is simplifed) if it wasnt asynch.

Upvotes: 10

Views: 4629

Answers (1)

adotout
adotout

Reputation: 1190

Unless there is some hidden functionality in the query function this is not possible. http://developer.chrome.com/extensions/tabs.html#method-query

Upvotes: 10

Related Questions