service-worker

Can a service worker fetch and cache cross-origin assets?

巧了我就是萌 提交于 2019-12-11 04:59:06
问题 I'm using some service worker code from the Progressive Web app tutorial by Google but I am getting an error: Uncaught (in promise) TypeError: Failed to execute 'clone' on 'Response': Response body is already used The site uses third-party Javascript and stylesheets for web fonts. I want to add assets hosted on these CDNs to the offline cache. addEventListener("fetch", function(e) { e.respondWith( caches.match(e.request).then(function(response) { return response || fetch(e.request).then

Firebase onMessage() not receiving messages

ⅰ亾dé卋堺 提交于 2019-12-11 04:54:14
问题 I'm developing a Firebase real-time messaging app. I've successfully managed to upload the browser/device token into the collection in the Firestore, but when I'm trying to test if the messages are being received in the app, I'm not getting any. Here are some parts of my code. <!-- The core Firebase JS SDK is always required and must be listed first --> <script src="https://www.gstatic.com/firebasejs/6.6.2/firebase-app.js"></script> <script src="https://www.gstatic.com/firebasejs/6.6.2

Chrome Application Cache deleted when going Offline

本秂侑毒 提交于 2019-12-11 04:47:51
问题 I intend using a Service Worker to make a Web App available offline. The cache Storage shows the files when I have Internet Connection. However if I go Offline the cache seems to disappear. I do not have enabled the checkbox of Update on Reload in the Service Workers tab. The fetch event of my service worker is: self.addEventListener('fetch', function(e) { console.log('[ServiceWorker] Fetch', e.request.url); e.respondWith( caches.match(e.request).then(function(response) { return response ||

Service Worker get from cache then update cache

梦想与她 提交于 2019-12-11 04:45:49
问题 I'm using the following logic in my service worker (in my own words): If cache exists, use it, but also update cache from the network for later event.respondWith( // on `fetch` caches.open(CACHE) .then(function(cache) { return cache.match(request); }) .then(function(matching) { if (matching) { requestAndUpdateCache(event); return matching; } ... In addition to responding with the cached response, I also run this function called requestAndUpdateCache . function requestAndUpdateCache(event){

Web push service worker registration error - Registration failed - could not retrieve the public key ?

半城伤御伤魂 提交于 2019-12-11 04:44:13
问题 When trying to install a service worker (Chrome 55), I'm getting this error in the browser console. Registration failed - could not retrieve the public key But this is happening only in the browser in one of the devices. In other devices in chrome 55, it's working fine. I'm not able to replicate this issue in other devices with the same chrome version. So I suppose this is not a problem with worker or manifest files. I would be very happy somebody could throw some light on this issue. 回答1: I

How to manually trigger a background sync (for testing)?

不想你离开。 提交于 2019-12-11 04:28:18
问题 In Chrome, is there any way to manually trigger a background sync for testing/development purposes? 回答1: You can now use a force sync in developer tools in Chrome on your service worker. Go Dev Tools --> Application --> Service Worker and you will see Sync button and next to it a space to write commands. 回答2: There's no way to do this in Chrome right now (April 2016). Follow this bug for updates. 来源: https://stackoverflow.com/questions/36718224/how-to-manually-trigger-a-background-sync-for

Android - PWA does not open in standalone mode with service worker

做~自己de王妃 提交于 2019-12-11 04:18:04
问题 While developing a Progressive-Web-App the following Problem occurred: Standalone mode works perfectly without including the service worker - but does NOT work with. Without Service-Worker a2hs (added to Homescreen) PWA gets correctly started in "standalone" -Mode. After adding the Service-Worker (a2hs + installed / Web-APK) PWA opens new Tab in new Chrome-Window. Chrome-PWA-Audit: login_mobile_tablet.jsf / include service worker: <script> if ('serviceWorker' in navigator) { navigator

notificationclick event service worker

孤街醉人 提交于 2019-12-11 03:42:23
问题 I'm working with service worker to display notification between my users. In my code I include notificationclick event. With this event I'm trying to manage two cases. First case, if in my browser the page of my site is opening, don't open it but focus on it. Second case, if my browser don't show my site, open it and focus on it. But I haven't been succed... Here is my current code: self.addEventListener('notificationclick', function (e) { console.log('notification was clicked') var

PWA debug chrome “add to homescreen” button not doing anything

ⅰ亾dé卋堺 提交于 2019-12-11 03:05:09
问题 I am trying to add the "add to Homescreen" prompt function to my website. Now I've read the google developer articles and I have everything set up. Now, If I try to manually add my page to the homescreen with the button "Add to homecreen" in the Chrome devtools > Application > Manifest , nothing is happening. A few times the console showed an error, but after fixing it nothing happens. I don't get the Add to shelf banner, but I don't get an error displayed in the console. Lighthouse doesn't

How to use service-worker if resources are on different domains?

穿精又带淫゛_ 提交于 2019-12-11 01:33:43
问题 As we know service worker is registered from the root of the project folder but, is there any way to fetch some static resources (css, js) from different domain(s)? Example : myWebsite.com // main url (e.g. index.html) abc.com/css/style.css // css file path xyz.com/js/jsFile.js //javascript file path 回答1: Any request that comes from the page (except iframe sub-resources) will pass through the service worker. These resources can be from the same or different origin. You can cache these