You can workaround the issue as follows (it's a bit like Ethernet protocols):
- Frontend: Include the tab's id to the message send to the Backend
- Backend: Broadcast the response to all tabs and include the received tab id in the message
- Frontend: Only tab with the matching tab id processes the response
Hence, using your code as a base, the solution would be as follows:
Backend:
appAPI.message.addListener({channel:"functionname"}, function(returnval) {
//Calculate some value v
appAPI.message.toAllTabs({tabId:returnval.tabId,rv:v}, {channel:"functionname_returnval"});
});
Frontend:
appAPI.message.addListener({channel:"functionname_returnval"}, function(message) {
// Check if message is for this tab
if (message.tabId === appAPI.getTabId()) {
//Do something with the return value (message.rv)
}
});
appAPI.message.toBackground({tabId:appAPI.getTabId(), ...},{channel:"functionname"});
Disclaimer: I am a Crossrider employee.