Hi all,
I need to migrate a browser extension to manifest V3 and I am facing an issue with message passing. I am new to this, so please forgive if my question seems novice.
We are using chrome.runtime.sendMessage() API to send a message via Popup:
class ChromeBroadcastService {
sendMessage(message: any, callback?: Function): void {
chrome.runtime.sendMessage(message, callback);
}
}
And we have defined a listener inside another class called ChromeSubscriptionService like this. It is supposed to listen to the sent message:
class ChromeSubscriptionService {
constructor() {
this.listenToMessages((notificationType: NotificationType, data: any, sendResponse: Function, sender: chrome.runtime.MessageSender) => {
// some method call
});
}
private listenToMessages(callback: Function): void {
chrome.runtime.onMessage.addListener((message: any, sender: chrome.runtime.MessageSender, sendResponse: Function) => {
if (message) {
callback(message.notificationType, message.data, sendResponse, sender);
if (sendResponse) {
return true;
} else {
return false;
}
}
});
}
}
This used to work
fine for manifest V2, but the listener is not able to receive the message for
V3. Is there anything that I am missing
here?
Thanks