service-worker

Redirection in progressive web app

泪湿孤枕 提交于 2019-12-04 09:06:38
I am trying to redirect to a particular url in progressive web app on notification click but it does not redirect. Case 1: If the web app is not added to home screen then on notification click the browser window opens up and is redirected to the desired url. Case 2: If the web app is added to home screen then the landing page is the home page and not the desired url. self.addEventListener('notificationclick', function(event) { event.notification.close(); event.waitUntil( clients.matchAll({ type: "window" }).then(function(clientList) { console.log(clientList); for (var i = 0; i < clientList

How do I sync data with remote database in case of offline-first applications?

那年仲夏 提交于 2019-12-04 08:38:51
问题 I am building a "TODO" application which uses Service Workers to cache the request's responses and in case a user is offline, the cached data is displayed to the user. The Server exposes an REST-ful endpoint which has POST, PUT, DELETE and GET endpoints exposed for the resources. Considering that when the user is offline and submitting a TODO item, I save that to local IndexedDB, but I can't send this POST request for the server since there is no network connection. The same is true for the

Chrome Service Worker iOS Support

孤街醉人 提交于 2019-12-04 06:18:35
As Apple announced Service Worker support for iOS 11.3 a few months ago, I recently started trying to get a service worker to work on iOS. On Safari it works as expected, after vising the website, it works offline. However, when trying to use the same feature in Chrome, I had intermittent results. Specifically, the service worker would only work every other page refresh, with the original refresh after going offline being one of the ones not working. I know that Chrome on iOS is built on a version of Safari, therefore I am confused about this behavior. Is this due to incomplete support from

Service Worker Response Cache Headers

核能气质少年 提交于 2019-12-04 06:13:04
I'm trying to figure out how the service worker works in regards to cache headers in responses. I have implemented a couple of service workers now but have never had to bother worrying about caching headers, how long items should be cached for etc. I'm now implementing it on an enterprise production site, whereby this stuff actually really matters. Basically when using a service worker, is the http cache completely bypassed? Do I then need to build a framework to handle resource expiration/invalidation like the http cache used to do for us? Or am I talking rubbish? Would be super helpful if

Open external links in webview as default in IOS PWA

好久不见. 提交于 2019-12-04 06:02:57
I'm testing Progressive Web App in IOS 11.3. My pwa has a Facebook social login button that, when clicked, points to an external link (different windows.location). The problem is that the pwa opens safari app to show external links instead of using a webview within the pwa. So, when the login is done, you will not be redirected to the pwa, but remains in safari. I tried following examples like this one: https://gist.github.com/kylebarrow/1042026 but seems not working How can I force the pwa to open external links in a webview? Thanks in advance This problem is solved in IOS 11.4 UPDATE

how to use Service Worker to cache cross domain resources if the response is 404?

北慕城南 提交于 2019-12-04 03:27:40
w3: 6.2 Cross-Origin Resources and CORS¶ Applications tend to cache items that come from a CDN or other origin. It is possible to request many of them directly using <script>, <img>, <video> and <link> elements. It would be hugely limiting if this sort of runtime collaboration broke when offline. Similarly, it is possible to XHR many sorts of off-origin resources when appropriate CORS headers are set. ServiceWorkers enable this by allowing Caches to fetch and cache off-origin items. Some restrictions apply, however. First, unlike same-origin resources which are managed in the Cache as Response

Why does Chrome keep displaying “Site cannot be installed: the page is not served from a secure origin” in the console?

我们两清 提交于 2019-12-04 03:21:32
问题 Whenever I look in Chrome's console, I see this error message: Site cannot be installed: the page is not served from a secure origin This only started happening a few days ago, and Chrome wasn't updated in the meantime. 回答1: This error is caused by sites served over HTTP if "Add to shelf" is enabled in chrome://flags. Solutiuon: go to chrome://flags/#enable-add-to-shelf and change "Enabled" to "Default", then relaunch chrome. 来源: https://stackoverflow.com/questions/41863050/why-does-chrome

Add more service-worker functionality with create-react-app

吃可爱长大的小学妹 提交于 2019-12-04 02:26:36
So create-react-app includes service worker functionality by default , which is lovely - all my static assets get cached for offline use out of the box. Cool, but now I want to take things a bit further and use indexedDB to cache some dynamic content. Problem is, there's no service-worker.js file to modify. It gets generated during the build process. Is there a way to add additional logic without ejecting create-react-app or redoing all the nice static caching stuff? As you've observed, create-react-app 's config is locked down, and the service worker logic is entirely defined in the config.

An unknown error occurred when fetching the script (Service Worker)

人走茶凉 提交于 2019-12-03 23:57:18
When going offline, I get the following error by my service worker: (unknown) #3016 An unknown error occurred when fetching the script my service worker looks like this: var version = 'v1' this.addEventListener('install', function(event){ event.waitUntil( caches.open(version).then(cache => { return cache.addAll([ 'https://fonts.googleapis.com/icon?family=Material+Icons', 'https://fonts.googleapis.com/css?family=Open+Sans:400,600,300', './index.html' ]) }) ) }) this.addEventListener('fetch', function(event) { event.respondWith( caches.match(event.request).then(function(resp) { // if it's not in

Prevent Service Worker from automatically stopping

情到浓时终转凉″ 提交于 2019-12-03 23:43:03
问题 Service Worker seems to automatically stop at some point. This behaviour unintentionally closes the WebSocket connection established on activate. When and Why does it stop? How can I programmatically disable this unexpected action to keep Service Worker stay running? 回答1: What you're seeing is the expected behavior, and it's not likely to change. Service workers intentionally have very short lifespans. They are "born" in response to a specific event ( install , activate , message , fetch ,