요청의 일부로 tabId를 백그라운드 코드로 전달하여 목표를 달성 할 수 있습니다. 백그라운드에서 모든 탭에 응답을 브로드 캐스트하고 원래 탭에서 메시지를 식별 할 수 있도록 메시지에 tabId를 보냅니다.
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: ...
});
});
});
[공개 : 나는 Crossrider입니다
다음 예는 원리를 보여줍니다 직원]