You can achieve your goal by passing the tabId as part of the request from the tab to the background code. In the background, broadcast the response to all tabs and send the tabId in the message so that the original tab can identify the message.
The following example demonstrates the principle:
extension.js:
appAPI.ready(function($) {
// Listener to handle incoming messages
appAPI.message.addListener(function(msg) {
// Check if the message is intended for this tad
if (msg.tabId === appAPI.getTabId()) {
// Your code here
}
});
// Send message to background
appAPI.message.toBackground({
// Pass the tabId with the message
tabId: appAPI.getTabId(),
yourData: ...
});
});
background.js:
appAPI.ready(function($) {
// Listener to handle incoming messages
appAPI.message.addListener(function(msg) {
// Send message to all tabs
appAPI.message.toAllTabs({
// Pass the tabId with the message to identification
tabId: msg.tabId,
yourData: ...
});
});
});
[Disclosure: I am a Crossrider employee]