I am start working with PWA (Progressive web app). When I try to check service worker is supported or not in chrome browser.It always return false. Below code I used for the checking.
Note: I am using chrome Version 69.0.3497.81 (Official Build) (64-bit).
app.js
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js').then(function() {
console.log('service worker registered');
});
}
Need help to register service worker in chrome.
From what I understand, service workers do not work on all browsers, but I checked to see if it runs in Chrome (which is what I'm testing in) and it says that service workers are supported. Can someone please tell me why it isn't working?
Since service workers don't have access to DOM, it's not possible for an extension's service worker to access the DOMParser API or create an <iframe> to parse and traverse documents. Extension developers have two ways to work around this limitation: create a new tab or use a library. Which you choose will depend on your use case.
In short: Service workers requires the site using them to be served over HTTPS for security reasons, but have execptions for localhost. Check this for how to serve your html file on localhost.
Service workers are a specialized kind of web worker, which are quite different from the web pages most web developers are used to working with. On a typical web page (or extension background page), the global execution context for JavaScript is of type Window.
This problem is cause due to I am running my application on http://192.168.1.11:8080 but when I switch domain to http://localhost:8080/. it's working fine.
Chrome requires service workers to be served over https, but allows an exception for localhost for development.
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