1

I have a Progressive Web App (PWA) that does not work offline on iPadOS if the Service Worker has a redundant "if (false) {} " in it.

To demonstrate the problem, I have set up 2 websites;

https://pwadoeswork.azurewebsites.net/ (this one does work offline) and

https://pwadoesnotwork.azurewebsites.net/ (this one does not work offline)

These differ only in the service worker. The one that does not work has the following entirely redundant code at the top...

if (false)
{
    self.addEventListener('fetch', () => { });
}
else
{
   :
   :
}

The "(false)" is generated by server-side code (Razor .net core) and it is true when running in Dev and false on Production (inspired in part by the Visual Studio Blazor PWA template when you create a new project)

The PWA installs and works offline on the PC, Android (phone, tablet with either Chrome or Samsung Internet) and iOS (mobile phone) precisely as expected. However, only on iPadOS (at least v15 & v16), after you have installed the PWA (Safari->Share->Add to Home Screen->Add) and run it, and then close it (multi-finger pinch and swipe the app off) and go to Aeroplane mode, and then run it from the Home Screen again, Safari reports that it is offline. If you do the same process with the version that does work (without the redundant code) then it runs offline as expected.

The only difference is the "if(false) {} " code. Needless to say, this should not impact anything.

Some questions;

Am I missing something here?

Is this just an iPadOS/Safari bug?

Does the iPadOS run some cut-down version of the javascript engine when running the service worker?

Are there any other hidden gotchas or limitations that I should be aware of that only impact iPadOS with PWA?

Is this behaviour documented somewhere?

DJA

DJA
  • 661
  • 1
  • 9
  • 25
  • I have a similar issue I am working through. Two Blazor PWAs with the same functionality and near identical service worker files. The difference is the one service worker has a comment automatically added during the build. The app with the comment in the service worker has the same behaviour as the pwadoesnotwork project. Will let you know when I work it out. – Michael Nov 13 '22 at 18:00
  • @michael, did you work it out? – DJA Nov 22 '22 at 11:19
  • @michael, did you work it out? – Palani Kumar Nov 24 '22 at 11:34

0 Answers0