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

Deadly 提交于 2020-01-02 03:40:11

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/17748101/chrome-extensions-make-chrome-tabs-query-synchronous

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!