Return about BroadcastChannel, I shared with you a simple example:
// service worker
const channel = new BroadcastChannel('YOUR_CHANNEL_NAME');
channel.onmessage = (msg) => {
console.log('message received from popup', msg);
channel.postMessage({ msg: 'Hello popup from service worker'});
};
// popup.js
const channel = new BroadcastChannel('YOUR_CHANNEL_NAME');
channel.onmessage = (msg) => {
console.log('message received from service worker', msg);
channel.postMessage({ msg: 'Hello service worker from popup'});
The service worker always wake up when received the message, so the first message should be from popup to service worker.
I hope you understand me the example ;-)