This question already has an answer here:
I have this piece of code in my background.js:
chrome.extension.onMessage.addListener( function(request,sender,sendResponse){
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
var requests = getTabRequests(tabs[0].id);
//getTabRequests gets all the information i stored about a tab
sendResponse( {requests: requests});
});
});
What I want it to do, is respond to the popup.js. The chrome.tabs.query
makes this impossible for me. I realise this is an asynchronous function, but how to fix it? Or is the only possibility to not send a response, but just another message in the different direction (which means i can't use the callback function in mu popup.js)
Read the documentation of
chrome.runtime.onMessage
:(
chrome.extension.onMessage
is deprecated, usechrome.runtime.onMessage
instead, the former is an alias of the latter though.)