Questions tagged [service-worker-events]

122 questions
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…
17
votes
5 answers

Firefox: Service Worker: SecurityError: DOMException: The Operation is insecure

In app.js, I am checking the serviceWorker existence in navigator object and if available then registering the SW. if ('serviceWorker' in navigator) { navigator.serviceWorker.register('./service-worker.js', { scope: './' }) …
16
votes
1 answer

Why my Service Worker is always waiting to activate?

I have this very basic question I'm striving to understand the Service Worker life cycle, or even better, what in practical terms initialize and change the states. I got 2 questions right now: 1 - in chrome://inspect/#service-workers there are…
Victor Ferreira
  • 5,153
  • 10
  • 53
  • 97
8
votes
2 answers

self.skipWaiting() not working in Service Worker

I have a service worker. Here's the install event: self.addEventListener('install', function (event) { console.log('Installing Service Worker ...', event); return self.skipWaiting() .then(() => caches.open(CACHE_STATIC_NAME)) …
Ethan
  • 2,231
  • 1
  • 16
  • 35
8
votes
1 answer

service workers: async await in combination with waituntil is not working properly

i'm struggling with promises in a service worker while using async/await syntax. Following situation: I got a push notification and want to handle the click event. If i use the "old" syntax with then and catch i can iteratore over the list of…
7
votes
1 answer

How to make service worker register only on the first visit?

Hi I have an ejs template on express which generates HTML. I have written my service worker registration code in this template which is common for all pages of the website and thus, the registration code ends up being there on every page of the…
7
votes
1 answer

Fetch event not receiving request headers

It seems that fetch event inside service worker isn't receiving request headers, although it is stated in MDN documentation: You can retrieve a lot of information about each request by calling parameters of the Request object returned by the…
7
votes
2 answers

Service worker error: event already responded to

I keep getting this error: Uncaught (in promise) DOMException: Failed to execute 'respondWith' on 'FetchEvent': The event has already been responded to. I know that service workers automatically respond if asynchronous stuff goes on within the…
Ethan
  • 2,231
  • 1
  • 16
  • 35
6
votes
2 answers

service worker notificationclick event doesn't focus or open my website in tab

I use FCM push notification in my website and I want user can come into my website when He or She clicks on the push notification. Please notes that The user may be in other app or in other browser tab and I want when the user gets fcm notification…
5
votes
1 answer

Background sync not firing event in serviceworker

My sync event not firing, am using chrome webserver to serve a page on my desktop PC on localhost:5000 and using a fetch api to POST data to the local development server on a separate port localhost:1337. Have turned off my wifi, the chrome…
5
votes
3 answers

Service Worker - Wait for clients.openWindow to complete before postMessage

I am using service worker to handle background notifications. When I receive a message, I'm creating a new Notification using self.registration.showNotification(title, { icon, body }). I'm watching for the click event on the notification using…
4
votes
2 answers

How to receive request payload in service worker?

I've used service worker to intercept HTTP requests to a secure resource and add authorization header to the request (if the the user is already logged in). Now, I have a scenario where a service worker intercepts a POST request to inject…
4
votes
0 answers

How to modify response body before caching inside a service worker?

I thought it would be rather simple but I am struggle to successfully send response then modify my cloned response that is being stored in cache inside my service worker. Ultimately I want to appended my cached data with the time and date of the…
4
votes
0 answers

How to implement effective two way communication with service worker and client web page

I want to implement effective 2 way communication between service worker and client web page. here is my code function twoWayMsg() { if (navigator.serviceWorker.controller) { var messageChannel = new MessageChannel(); …
4
votes
0 answers

Web Push Notification (using service worker)

Am following this project to add web push notifications using service-worker Push Notifications and ASP.NET Core and the complete project Demo.AspNetCore.PushNotifications. Everything works fine, my only problem here is that when I send 2 or more…
1
2 3
8 9