service-worker

clients.openWindow() “Not allowed to open a window.” on a serviceWorker Google Chrome

谁说胖子不能爱 提交于 2019-12-05 00:12:40
I'm testing under Chrome Version 42.0.2311.152m and I want to implement to open a window on a notificationclick like in this example: (source: https://developer.mozilla.org/en-US/docs/Web/API/WindowClient ) self.addEventListener('notificationclick', function(event) { console.log('On notification click: ', event.notification.tag); event.notification.close(); // This looks to see if the current is already open and // focuses if it is event.waitUntil(clients.matchAll({ type: "window" }).then(function(clientList) { for (var i = 0; i < clientList.length; i++) { var client = clientList[i]; if

I need to access localstorage or cookie from within the serviceworker

跟風遠走 提交于 2019-12-05 00:02:47
I wish to make a fetch call after the push event for fetching the notif data through an internal api with user specific params which are stored in the localstorage or cookie such as usertype or country id .. how do i do this ? You cannot use Local Storage in service workers. It was decided that service workers should not have access to any synchronous APIs. You can use IndexedDB instead, or communicate with the controlled page using postMessage() . By default, cookies are not included with fetch requests, but you can include them as follows: fetch(url, {credentials: 'include'}) . 来源: https:/

“Corrupted Content Error” on Firefox with Polymer/Firebase

冷暖自知 提交于 2019-12-04 20:16:20
I have a Polymer app with service workers hosted with Firebase. The app works fine on every browser except Firefox. When you try to refresh the browser in Firefox after initial load (which works), it throws the following error: A ServiceWorker passed a redirected Response to FetchEvent.respondWith() while RedirectMode is not ‘follow’ The service-worker.js is auto-generated by the polymer-cli (v0.16.0). To address this known issue , set the redirect option to follow in your service worker's fetch() requests: fetch(..., { redirect: 'follow' }) 来源: https://stackoverflow.com/questions/40274429

FCM: Cannot click notification

有些话、适合烂在心里 提交于 2019-12-04 19:25:36
问题 I'm using the recently release FCM messaging support for push notifications on the chrome. When my app is in the background, I get the notification but nothing happens when I click the notification. How to I specify the URL which should open when the user clicks the notification? (I understand how its done using the pure service worker concept using the notificationclick event, I want to know how to do that using FCM messaging.) messaging.setBackgroundMessageHandler(function(payload) { var

Service worker update delay

女生的网名这么多〃 提交于 2019-12-04 19:25:36
I have a web app that is working and relying on service workers to keep all the cached files in check and to make sure users are on the correct version of the app. Our client is currently wanting the device to check for an update at specific points (When reopening the app) etc, as currently when you open the app it can take up to 5minutes before the device realises its on an outdated version. Am I able to force the device to check the service worker for any new changes instead of waiting for the app to check for me? Thanks! There are two main points you should refine for instant update of your

Check Service worker installation progress from component (angular)

我与影子孤独终老i 提交于 2019-12-04 18:33:45
I have updated my angular app into PWA, since I need to preload all of the assets on the first launch (application have a lots of images, which are used for UI). That's why I would like to show some kind of spinner/loading bar during service worker install event and hide it when it's done. So first question - is it possible to handle this event from the component? I have found this example and tried to add it inside first component, that loads on app launch, but didn't get any logs. So probably it doesn't work that way. ngOnInit() { self.addEventListener('install', event => { this.log(

Get page URL parameters from a service worker

旧街凉风 提交于 2019-12-04 18:15:09
How do I get page URL with parameters from a service worker? I have tried self.registration.scope but that doesn't include the parameters. I'm not clear as to whether you're asking about getting the service worker script's URL, or the URLs of all of the client pages that are open under the service worker's scope. So... here's how to do both: // Get a URL object for the service worker script's location. const swScriptUrl = new URL(self.location); // Get URL objects for each client's location. self.clients.matchAll({includeUncontrolled: true}).then(clients => { for (const client of clients) {

navigator.serviceWorker.controller is always null

我只是一个虾纸丫 提交于 2019-12-04 17:17:11
问题 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 =

How to remove a service worker registered in previous deploy from users' browsers with the newly deployed version of site (Firebase)?

痴心易碎 提交于 2019-12-04 17:13:28
I've deployed a new version of my site (It was on Polymer, now on Vue.js) to Firebase over an existing project. I'm using default Vue.js template with Webpack ( vue init webpack my-project ) in the new project Now that I've deployed the new version, when I open the site I see just a cached shell, I assume that's the service worker's fault In order to get actual current files from Firebase I (and all the previous visitors) have to now hard refresh the site every time ( Ctrl+F5 in firefox) Console Now, in browser console (network tab) I see: The service worker in red, it says: (failed) net::ERR

Comparison between service worker and AppCache

老子叫甜甜 提交于 2019-12-04 16:45:38
问题 What are the core differences between service worker and AppCache. What are the pros and cons of each and when to prefer one over another . 回答1: The primary difference is that AppCache is a high-level, declarative API, with which you specify the set of resources you'd like the browser to cache; whereas Service Worker is a low-level, imperative, event-driven API with which you write a script that can intercept fetch events and cache their responses along with doing other things (like