Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Service Worker working on Chrome Lighthouse?

Tags:

lighthouse

I am trying to audit my application on Chrome Lighthouse, but I can't get Service Worker working. It is registered and running with no error, but when I try to run Lighthouse it gets stuck and console log the fallowing error:

Service worker not registered  DOMException: Failed to register a ServiceWorker for scope ('https://www.localhost.com/') with script ('https://www.localhost.com/sw.js'): Operation has been aborted

SW is called with:

    if('serviceWorker' in navigator){
    let sw = 'sw.js';
    navigator.serviceWorker.register(sw, {scope: "/"})
        .then(function(){
            console.log('Service worker registered.');
        })
        .catch(function(e){
            console.log('Service worker not registered ', e);
        })
}

In the manifest:

start_url: "/",
    scope: "/",

I also tried:

"../", "https://www.localhost.com/", "./",

I am running chrome with the flags:

"C:\Program Files\Google\Chrome\Application\chrome.exe" --ignore-certificate-errors --unsafely-treat-insecure-origin-as-secure=https://www.localhost.com

But, I also tried to run the application in a remote server with https and I got the same error.

Any help would be nice.

like image 553
Joel Avatar asked Oct 27 '21 14:10

Joel


People also ask

Does not register a service worker that controls page and?

“Does not register a service worker that controls page and start_url. The service worker is the technology that enables your app to use many Progressive Web App features, such as offline, add to homescreen, and push notifications.”

What is Lighthouse plugin?

Lighthouse is an open-source, automated tool for improving the quality of web pages. You can run it against any web page, public or requiring authentication. It has audits for performance, accessibility, progressive web apps, and more.


1 Answers

If I uncheck the clear cache option in lighthouse options it starts working.

Edit: As mentioned by Sean McCarthy below the correct name is "Clear storage"

like image 190
Joel Avatar answered Oct 25 '22 22:10

Joel