service-worker

unable to post message to service worker because controller value is null

↘锁芯ラ 提交于 2019-12-10 17:18:05
问题 I am trying to make a website available offline with the help of service workers to cache the files needed by the page. I am trying to give the user control over which images he wishes to cache. For this, I am using a function sendMessage function sendMessage(msg){ navigator.serviceWorker.controller.postMessage(msg); } where message contains data relative to the image that the user wishes to cache or un-cache. The service worker contains an event listener for the message event: this

Angular Service Worker, caching api calls for offline app

白昼怎懂夜的黑 提交于 2019-12-10 17:11:34
问题 I'm trying to make the service worker in angular work with API requests. I'd like the app to work offline and I've the below config: { "name": "api", "urls": ["https://x.com/**"], "cacheConfig": { "strategy": "performance", "maxSize": 20, "maxAge": "365d", "timeout": "5s" } } Here is what the xhr tab looks like when I'm offline: and this is the content of the user request: As you can see the API calls for user don't resolve. This is what the response of user looks like when online: 回答1: Try

Check if window is active from Service Worker

元气小坏坏 提交于 2019-12-10 15:31:51
问题 I'm trying to run a Web Application that sends push notifications when the window is inactive. To do this, I have a Service Worker that helps receives notifications from my php server (through Firebase). However, I'm unsure how to check if the window is active through my Service worker. The Service Worker does not have access to the DOM, so I can't check it directly through there, and I've tried doing the checks on an attached JS file, but the Service Worker gets variable not defined errors.

Read env variable from service worker file using workbox

感情迁移 提交于 2019-12-10 14:46:52
问题 I'm working with workbox-sw and workbox-webpack-plugin My src sw.js file at root folder (same level with my .env file) How can I get env variables and accessing it into my src sw.js file This is from my webpack.config.js new workboxPlugin({ globDirectory: 'dist', globPatterns: ['**/*.{html,js,css,svg,otf,png,jpg,gif}'], swSrc: './sw.js', swDest: path.join('public', 'sw.js') }) Every help will be appreciated! Thanks everyone! 回答1: Because you're using swSrc: './sw.js' , that implies that the .

Service Worker not working in Offline mode with node js server

橙三吉。 提交于 2019-12-10 13:32:51
问题 I am trying to build a PWA with an offline first policy. The server for the source files is a NodeJS server . I am currently testing this on a localhost node server (not sure it has an impact ?). Service worker + caching seems fine, but in offline mode I only get the Chrome Offline Page . Let's get into details : The page which is served (through the http://localhost:8080/place/test url) has some client side JS, in which I register a Service Worker : client.js if ('serviceWorker' in navigator

firebase cloud messaging: setBackgroundMessageHandler not called

主宰稳场 提交于 2019-12-10 12:40:09
问题 I am prototyping browser push notifications with FCM. I just copied the example code from the quickstart (https://github.com/firebase/quickstart-js/tree/master/messaging). Messages are recieved and displayed as they should be. But when I try to modify the message in the Service Worker (messaging.setBackgroundMessageHandler) nothing happens. The service worker is called, and if I implement an event listener in that service worker for the push notifications, it catches the event. But the method

How to unregister and remove old service worker?

假如想象 提交于 2019-12-10 12:19:22
问题 I have register a service woker using .register and can see in Application tab in dev tool. now my questionn is how to unregister this service worker. I have run this script if ('serviceWorker' in navigator) { window.addEventListener('load', function() { console.group('====SW registration======='); navigator.serviceWorker.register('/sw.js', {scope: './'}).then(function(registration) { console.log('SW registratered successfully'); console.log(registration); registration.unregister().then

Service Worker slow response times for css

蹲街弑〆低调 提交于 2019-12-10 10:49:58
问题 We have service worker written on top of sw-toolbox. Once the static resources are cached service worker is taking longer time especially for downloading css resources (30 - 100ms) where as for js resources the time is almost 0. CSS load times : Load 1 : 35ms Load 2 : 25ms Load 3 : 101ms Load 4 : 22ms Js load times : Load 1 : 0 ms Load 2 : 0 ms Load 3 : 0 ms Load 4 : 0 ms Question : 1.Why css load times are higher with service worker? Would be really helpful to us if someone can provide

iOS 12 does not support offline feature of some PWAs

半城伤御伤魂 提交于 2019-12-10 10:25:05
问题 iOS 12 Safari does not support the offline feature of some PWAs (Progressive Web App). It seems like Safari does not cache resources in those web apps properly. For example, the following PWAs cannot work offline in iOS 12 and 12.1, but they all work perfectly in Chrome on Android or Windows: The Air Horner PWA that is used by google to demonstrate Service Worker: Air Horner And these two: 2048 puzzle Voice Memos Steps to reproduce (100% reproducible): visit the PWA with Safari (iOS 12 or 12

Can Service Worker push notification without gcm in chrome ?

☆樱花仙子☆ 提交于 2019-12-09 22:56:46
问题 Google's service include GCM can not access in my country.Can Service Worker push notification without gcm in chrome? Or if some hack technique can implement this? 回答1: Chrome now also uses Firebase Cloud Messaging as its Push Service, which may be available in your country. You could also use a third party Push Notification platform. These would still need to access GCM or FCM but they might have some ways to get access in restricted areas. Just do a search for "push notification third party