Questions tagged [service-worker]

A service worker is JavaScript code that, once registered with an associated origin and scope, will respond to browser-initiated events, even when the pages it controls are no longer open. By handling `fetch` events, service workers can provide custom network behavior, like offline support (via the Cache API). By handling `push` events, service workers can be "woken up" and display notifications.


4030 questions
30
votes
6 answers

404 error when trying to register serviceWorker

I get this error when trying to register the service worker: Failed to register a ServiceWorker: A bad HTTP response code (404) was gwreceived when fetching the script. I'm working with ionic and this is what I have in the app.js: if…
George Cscnt
  • 481
  • 2
  • 6
  • 13
29
votes
12 answers

Uncaught TypeError: Cannot read property 'id' of undefined at registerNgModuleType - angular PWA

after adding @angular/pwa to my app ng add @angular/pwa --project appName I get error core.js:34469 Uncaught TypeError: Cannot read property 'id' of undefined at registerNgModuleType If I in my appName.module.ts remove from…
Arter
  • 1,726
  • 2
  • 15
  • 43
29
votes
3 answers

Does service worker runs on background even if browser is closed?

I see push notification for Facebook web in chrome only when I open chrome. I know that this notification are sent through service worker. I am wondering whether this background sync goes on even though browser is closed or only on opening chrome…
27
votes
1 answer

Is it possible to track geolocation with a service worker while PWA is not open

Is it possible to read from local storage and track geolocation in PWAs with a service worker while app is not open on phone (in background) So far my research is pointing to no, and I am finding that the PWA needs to be open for location…
27
votes
3 answers

How to clear a Service Worker cache in Firefox?

In Chrome it is possible to clear the Service Worker cache from the Dev Tools. How can we achieve that in Firefox? I've tried so far: to unregister the service in about:serviceworkers to empty the cache under about:preferences#privacy to reload…
Supersharp
  • 23,488
  • 6
  • 68
  • 109
27
votes
3 answers

Use ServiceWorker cache only when offline

I'm trying to integrate service workers into my app, but I've found the service worker tries to retrieve cached content even when online, but I want it to prefer the network in these situations. How can I do this? Below is the code I have now, but I…
Ruben Martinez Jr.
  • 3,115
  • 5
  • 37
  • 67
26
votes
2 answers

Should i cache manifest.json in service worker

I am using service worker. Should I cache my manifest.json file. Does it makes sense? Also how frequently does the browser fetch this file.
aWebDeveloper
  • 31,131
  • 35
  • 150
  • 224
26
votes
2 answers

Service Worker Registration Failed

I am currently working on service worker to handle push notification in browser. Currently I am having this "SW registration failed error": SW registration failed with error SecurityError: Failed to register a ServiceWorker: The URL protocol of the…
Saugat Bhattarai
  • 1,926
  • 3
  • 21
  • 31
26
votes
4 answers

Application Cache or Service Workers - which to use in 2016/Q2?

Quick question for discussion really, as I wanted to have input from different people. I am in the process of developing a web page app that must be available offline. Now to do this, as I understand it, you would go about using either the…
25
votes
2 answers

Passing state info into a service worker before `install`

Background I'm new to service workers but working on a library that is intended to become "offline-first" (really, almost "offline-only") (FWIW, the intent is to allow consumers of the library to provide JSON config representing tabular multilinear…
Brett Zamir
  • 12,481
  • 5
  • 45
  • 68
25
votes
5 answers

Android Back Button on a Progressive Web Application closes de App

Can a "pure" HTML5/Javascript (progressive) web application intercept the mobile device back button in order to avoid the App to exit? This question is similar to this one but I want to know if it is possible to achieve such behavior without…
rmpestano
  • 687
  • 1
  • 6
  • 16
25
votes
2 answers

Disable service workers when in development mode.

In case of our development, we serve files from https://localhost as the app is hosted in salesforce.com. In chrome service worker on chrome blocks anything coming from self-signed server i.e (https://localhost). So is there a way to…
Kiba
  • 8,180
  • 6
  • 24
  • 30
24
votes
2 answers

503 ok (from serviceWorker)

I used @angular/service-worker to generate SW for an angular4 web app. after updating the ngsw-manifest.json to handle dynamic request from the server I get "Status Code:503 OK (from ServiceWorker)" when offline (after first loading). Any thoughts?
Tomer Kohn
  • 243
  • 1
  • 6
24
votes
6 answers

How to force service worker to update?

I'm using sw-precache to generate my service work with Polymer CLI build process, so it's intended to update the hash of updated files to signal a need to update the cache. But my updated content is not being replaced in cache, so it's getting an…
Jp_
  • 4,771
  • 4
  • 21
  • 32
23
votes
1 answer

C# worker service vs windows service

What is the big difference between the worker service project template and the windows service project template and which is better to use? When can I use a worker service & windows service?