Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 602
kajacx Avatar asked Jul 19 '13 14:07

kajacx


People also ask

How do I make Chrome tabs always active?

Open the Chrome menu (click the 3-dot menu in the upper-right corner of Chrome) Click Settings. Scroll to the On Startup section at the bottom of the page. Click to enable the setting Continue where you left off.

How do I iterate through a tab in Chrome?

Close the chrome://inspect/#pages page. You can use sendkeys Ctrl & 1 to move to the first tab and the use the sendkeys Ctrl & Tab to iterate through the tabs.

How do I open a new tab in the same window in Chrome?

Windows & Linux: Ctrl + t. Mac: ⌘ + t.

How do I find my Chrome tab ID?

From there, the tab ID is accessible via 'sender.tab.id'. See http://code.google.com/chrome/extensions/messaging.html for more info. You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.


1 Answers

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

like image 143
adotout Avatar answered Oct 01 '22 02:10

adotout