Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Service Worker failure - Redirected response while RedirectMode is not "follow"

Browser: Firefox 58.0.2 (64-bit)

I'm trying to write a very simple service worker to cache content for offline mode, following the guidance here and here.

When I load the page the first time, the service worker is installed properly. I can confirm it's running by looking in about:debugging#workers.

However, at this point if I attempt to refresh the page (whether online or offline), or navigate to any other page in the site, I get the following error:

The site at https://[my url] has experienced a network protocol violation that cannot be repaired.

The page you are trying to view cannot be shown because an error in the data transmission was detected.

Please contact the website owners to inform them of this problem.

The console shows this error:

Failed to load ‘https://[my url]’. A ServiceWorker passed a redirected Response to FetchEvent.respondWith() while RedirectMode is not ‘follow’.

In Chrome, I get this:

Uncaught (in promise) TypeError: Failed to execute 'fetch' on 'ServiceWorkerGlobalScope': Cannot construct a Request with a Request whose mode is 'navigate' and a non-empty RequestInit.

Per this thread, I added the { redirect: "follow" } parameter to the fetch() function, but to no avail.

(Yes I did manually uninstall the Service Worker from the about:debugging page after making the change.)

From what I understand, however, it's the response, not the fetch, that's causing the problem, right? And this is due to my server issuing a redirect when serving the requested content?

So how do I deal with redirects in the service worker? There are obviously going to be some, and I still want to cache the data.

like image 777
Ryan Griggs Avatar asked Apr 24 '18 18:04

Ryan Griggs


1 Answers

Partly spun off from https://superuser.com/a/1388762/84988

I sometimes get the problem with Gmail with Waterfox 56.2.6 on FreeBSD-CURRENT. (Waterfox 56 was based on Firefox 56.0.2.) Sometimes when simply reloading the page; sometimes when loading the page in a restored session; and so on.

FetchEvent.respondWith() | MDN begins with an alert:

This is an experimental technology

At a glance, the two bugs found by https://bugzilla.mozilla.org/buglist.cgi?quicksearch=FetchEvent.respondWith%28%29 are unrelated.

Across the Internet there are numerous reports, from users of Gmail with Firefox, of Corrupted Content Error, network protocol violation etc.. Found:

  • Mozilla bug 1495275 - Corrupted Content Error for gmail
like image 190
Graham Perrin Avatar answered Oct 13 '22 11:10

Graham Perrin