FAQ Database Discussion Community


Chrome ServiceWorker postMessage

google-chrome,message,postmessage,service-worker
I try to postMessage between a WebApp and the corresponding ServiceWorker. The serviceWoker is successfully registered and working so far. Unfortunately I noticed some strange behavior: 1. The navigator.serviceWorker.controller is always null. 2. At the serviceWorker side I implemented postMessage this way: self.addEventListener('message', function (evt) { console.log('postMessage received', evt);...

Posting messages from a service worker to a client page

javascript,service-worker
Today we can find many examples of sending message from a service worker to a client, but always following the reception of a message event in the service worker. I would like to know if we can send messages independently of this event? And if yes, how? I tried few...

ServiceWorker and Push Notification Payload

node.js,android-gcm,ecmascript-6,service-worker,chrome-gcm
Community: ServiceWorker is a great advance technology in terms of cache managment, but I have some questions associated with other operations such as: Push Notification: I made a GCM integration (Google Clud Message) and NodeJS, following this article, the problem is that when GCM sends the information to the client...

Is 'Service Worker' support offline HTML form data?

javascript,security,caching,privacy,service-worker
Service Workers essentially act as proxy servers that sit between web applications. My concern: Is ServiceWorker also support for offline forms? - If so then my other list of concerns are: Where it stored the incomplete HTML form data at client side (Storage, Session, Local, Database)? In which form it...

Why do service workers only work over HTTPS?

html5,service-worker
Per the original proposal, regarding "Prefer Secure Origins For Powerful New Features" “Particularly powerful” would mean things like: features that handle personally-identifiable information, features that handle high-value information like credentials or payment instruments, features that provide the origin with control over the UA's trustworthy/native UI, access to sensors on the...

Failed to register a ServiceWorker: ServiceWorker cannot be started

service-worker
Everything was working fine with my Service Worker project, but suddenly I am seeing the following error: Uncaught (in promise) DOMException: Failed to register a ServiceWorker: ServiceWorker cannot be started This is being reported as on index.html:1 although I am registering the SW in a file called sw.js. I couldn't...

Cache strategy for ServiceWorker

javascript,browser-cache,service-worker
What cache strategies are you using? I read the Offline Cookbook and the simplest strategy to use is to cache static content and the left out the API calls. This strategy seems something like this: Check if the request is already in cache If not add the request, response pair...

navigator.serviceWorker.controller is always null

google-chrome,service-worker
I have the problem that after registering the serviceWorker the navigator.serviceWorker.controller is always null. I never do a force refresh and just refresh the page. I test it with Google Chrome 42.0.2311.152 m (32-Bit). var currentServiceWorker = null; navigator.serviceWorker.register(SERVICE_WORKER_URL).then(function(serviceWorkerRegistration { if (navigator.serviceWorker.controller) { currentServiceWorker = navigator.serviceWorker.controller; } else { currentServiceWorker...

Service Workers and iOS

ios,service-worker
On Chromium's page about Service Workers there's noted that Service Workers are not supported by Chrome on iOS. I assume that it can be delivered to iOS using some cordova plugins. Is there any other way to use Service Workers on iOS devices? I'm worried about time between shipping new...

What is the API for unregistering service workers in Chrome >= 44?

service-worker
I'm trying to unregister a service worker that's already installed. I understand that the registration promise passes the registration as an argument to the success function and I could store that in some scope, but that wouldn't work after a page reload (I'd like to be able to unregister a...

Storing REST requests with service workers to sync them

javascript,offline,service-worker
I'm thinking about taking my application to offline using service workers. I'm already achieving satisfying results with caching resources, but I also have to check onfetch whether I'm connected to the internet, if not - store the request, and push it onsync. I understand, that future onsync will help with...

Offline web application with rewritten URL's

.htaccess,application-cache,service-worker
Using the Application Cache I can easily make my web application available offline and it works perfectly. The problem I am encountering is that I have recently started using a .htaccess file to rewrite urls from http://www.example.com/?/page to http://www.example.com/page After loading the 'homepage' in principal everything still works (as all...

PostMessage from serviceWorker after push event

javascript,postmessage,service-worker
I need to send message from serviceWorker to page after push-event. I can't specify the port property (like https://jakearchibald.github.io/isserviceworkerready/demos/postMessage/) because I did not send this message This code does not work (maybe I'm doing something wrong) self.registration.active.postMessage('fsdfasf'); ...

How can I get the size and/or number of elements in a ServiceWorker cache?

caching,quota,service-worker
ServiceWorker is a new api available in Chrome. One of the many things it lets you do is intercept network requests and respond with a cached version. I'm implementing a "take this offline" button which dynamically adds things to the cache. I'd like to report to the user how much...

Difference between serviceWorker.getRegistration and serviceWorker.ready.then

service-worker
I'm writing my first app with Service Workers and am trying to get the registration in order to interact with the pushManager. I can do this with either of the following: nagivator.serviceWorker.getRegistration() or navigator.serviceWorker.ready.then() Which should I use and what is the difference?...

How do I call a method on my ServiceWorker from within my page?

service-worker
I have a ServiceWorker registered on my page and want to pass some data to it so it can be stored in an IndexedDB and used later for network requests (it's an access token). Is the correct thing just to use network requests and catch them on the SW side...

Send Push Notification to everyone with Service Worker

push-notification,service-worker,chrome-gcm
curl --header "Authorization: key=blahblahblah" --header Content-Type:"application/json" https://android.googleapis.com/gcm/send -d "{\"registration_ids\":[\"blahblahblah\"]}" Currently i am able to send push notification though the command above. In order to send the notification to user, i need to get the registration id from user. What if I want to push notification to everyone (who subscribed to...

404 error when trying to register serviceWorker

javascript,service-worker
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 ('serviceWorker' in navigator) { navigator.serviceWorker.register('service-worker.js').then(function(registration) { console.log('ServiceWorker registration...

HTML5 Push Notifications - examples of other ways to push

html5,amazon-web-services,azure-mobile-services,service-worker
At Google IO 2015, there was a lot of talk of the push notifications for Chrome with HTML5 and service workers. It's early days, and examples are thin on the ground. I'm looking for server side examples of how to implement the push from platforms other than Google Cloud Messaging...

navigator.serviceWorker is never ready

service-worker
I registered a service worker successfully, but then the code navigator.serviceWorker.ready.then(function(serviceWorkerRegistration) { // Do we already have a push message subscription? .... hangs -- the function is never called. Why?...

ServiceWorker: when are the files actually cached?

caching,service-worker
I'm using a ServiceWorker to cache some assets and I want to let the user know once all the files have been successfully cached, so they're aware the content is accessible offline. When is the right moment to do this? I have several console.log() to have an idea of the...

How can we check if response for the request came from Service Worker

javascript,offline,service-worker
In Google Chrome console next to the status code of HTTP Request we have info (from ServiceWorker). Can Request be aware somehow that the Response came from ServiceWorker? Comparing date from Response Headers maybe?