lxieyang / chrome-extension-boilerplate-react

A Chrome Extensions boilerplate using React 18 and Webpack 5.
MIT License
3.47k stars 1.08k forks source link

Service worker goes to inactive forever after I restart brower #122

Open tungnnt opened 2 years ago

tungnnt commented 2 years ago

Hello, I successfully create an chrome extension from your template. I use chrome.tabs.sendMessage from Popup to send message to Content script. Content script use chrome.runtime.onMessage.addListener to listen event from Popup, then use chrome.runtime.sendMessage to send message to Service worker (Background in your template). In Service worker, I also use chrome.runtime.onMessage.addListener to listen message from Service worker. I install my extension for the first time into my browser and it runs perfectly. However, after I restart chrome, the extension stops working because Popup sends message to Content Script, Content Script sends message to Service worker but Service worker is inactive (in chrome://extension, it says: service worker (Inactive)). Please give some advices. Thanks in advance.

guntiss commented 2 years ago

I've been experiencing issues with service worker ever since MV3 and can't seem no narrow it down. It seems that mostly whenever I make some changes (webpack does compilation) Service worker starts misbehaving and all message communication between SW and Popup stops working. I've tried disabling HotModuleReplacement Plugin but still after every change I need to reload extension around 1-3 times to get it working, which is extremely annoying since it often even stops working after a while without making any changes.

As far as I understand it's expected that SW can be killed (become inactive) at any time, but it should automatically wake up when content script or popup is sending message, which is not the case for me. I'm guessing maybe something goes wrong with the listeners, but can't seem to figure out a solution.

kyrofox commented 2 years ago

anyone figure this out?