I am creating an extension using manifest V3 with a service worker that is set to listen for "webRequest.onBeforeRequest"
chrome.webRequest.onBeforeRequest.addListener(function(requestDetails) { . . . }, { urls: ['<all_urls>'] }, ['requestBody']);
On my personal machine (windows), the extension works as expected and the service worker starts whenever there is a web request in any of the tabs.
However, on our work machines (mac), the web requests do not automatically start the service worker. If I manually start it, it receives the events and functions properly, but as soon as it is stopped due to being idle, it does not re-start on the next web request. If I go to "chrome://serviceworker-internals/", I can see that the service worker is still registered, but is stopped.
My only way of keep the extension functioning has been to keep the developer tools page for the service worker open (via inspecting it), so that it continues to work by simply never stopping.
Is there something specific that I need to to do for mac OS or are there any settings or policies that can limit what events a stopped service-worker can listen for?
Outdated Extensions Check if the extension, which isn't loading properly, has been updated. Chrome usually updates extensions automatically whenever a new version becomes available. Still, it may take some time until its following schedule to verify whether any updates are available for extensions.
As stated in Service Workers: an Introduction, a "service worker is a script that your browser runs in the background, separate from a web page, opening the door to features that don't need a web page or user interaction." This is the technology that enables native-like experiences such as push notifications, rich ...
Because service-worker is able to send push notification only after I open the browser. If it is running in the background then it could have send notification even after closing browser also.
Would have put this in the comments, but don't have enough reputation to comment. I tried to solve this by having a setTimeout loop every 10 seconds (which is also something Gregory Conrad suggested in the comments) but unfortunately this didn't work the service worker still went inactive. In the comments someone said this is a known bug, but it seems like it might not be a bug, it could be intentional: https://www.eff.org/deeplinks/2021/12/chrome-users-beware-manifest-v3-deceitful-and-threatening. As the link says, service workers make it harder for browser extensions such as AdBlock to work as effectively, something which would benefit Google as they run a major internet advertising network.
I faced the same problem. Inserting code like the following seems to fix the problem. If I didn't set the callback function, it didn't work.
//content_script.js
var wakeup = function(){
setTimeout(function(){
chrome.runtime.sendMessage('ping', function(response){
console.log(response);
});
wakeup();
}, 1000);
}
wakeup();
//background.js
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse){
if( request == "ping" ){
console.log(request);
sendResponse("pong");
return;
}
sendResponse();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With