Service worker code preventing form submissions

21 views
Skip to first unread message

mostwanted

unread,
Jul 27, 2022, 2:04:34 AMJul 27
to web2py-users
I have this code below for a service worker, its primary purpose was for it to serve an offline page when the user is offline, it works ok as intended but the problem its causing now is that its preventing forms from submitting & other pages from opening!! Its javascript but i was hoping to get help from this platform nonetheless

'use strict';
var cacheVersion = 1;
var currentCache = {
  offline: 'offline-cache' + cacheVersion
};
const offlineUrl = '//off_line';
this.addEventListener('install', event => {
  event.waitUntil(
    caches.open(currentCache.offline).then(function(cache) {
      return cache.addAll([
          '/offline_Image.png',
          '/sesoa_banner.png',
         '/bootstrap.min.css',
          '/web2py-bootstrap3.css',
          '/mystyle.css',
          offlineUrl
      ]);
    })
  );
});

this.addEventListener('fetch', event => {
  // request.mode = navigate isn't supported in all browsers
  // so include a check for Accept: text/html header.
  if (event.request.mode === 'navigate' || (event.request.method === 'GET' && event.request.headers.get('accept').includes('text/html'))) {
        event.respondWith(
          fetch(event.request.url).catch(error => {
              // Return the offline page
              return caches.match(offlineUrl);
          })
    );
  }
    else{
        // Respond with everything else if we can
        event.respondWith(caches.match(event.request)
                        .then(function (response) {
                        return response || fetch(event.request);
                    })
            );
      }

});

Regards
Reply all
Reply to author
Forward
0 new messages