cloudinary / cloudinary_js

Cloudinary JavaScript library
MIT License
328 stars 224 forks source link

Serviceworker and cloudinary upload progress #199

Closed donv closed 4 years ago

donv commented 4 years ago

Hi!

I have a PWA and when I register a service worker with an event handler for the fetch event, all the Cloudinary upload progress events are missing. Doing a full refresh of the page enables the progress events for the current page, so does not registering an event handler for the fetch event.

My event handler should be pretty standard:

function onFetch(event) {
  event.respondWith(
    fetch(event.request).catch(function() {
      return caches.match(event.request).then(function(response) {
        if (response) { return response; }
        if (event.request.mode === 'navigate' ||
          (event.request.method === 'GET' && event.request.headers.get('accept').includes('text/html'))) {
          return caches.match('/offline.html');
        }
      })
    })
  );
}

self.addEventListener('fetch', onFetch);

Any idea what I am doing wrong? I get the same behaviour in the "Photo Album" Rails example app if I register a service worker..

donv commented 4 years ago

Hi!

I found an answer on StackOverflow: https://stackoverflow.com/a/54448464/658690 Disabling the fetch event handler for post requests did the trick:

function onFetch(event) {
    if (event.request.method === "POST") {
        return;
    }
    ...