pwa-builder/PWABuilder

[BUG] App fails to load in airplane mode

Opened this issue ยท 13 comments

What happened?

If I start the app (with the service worker happy and running) the page will not load. Inspecting the web view shows that navigator.serviceWorker is not defined in this state.

How do we reproduce the behavior?

  1. Install app
  2. Launch and kill app
  3. Wait until the cache expires
  4. Launch app
  5. App fails to load and shows connection indicator

What do you expect to happen?

App loads

What environment were you using?

iOS 17.7

Additional context

To me it seem that WKWebView does not properly initialise the service worker / registration properly if the first page load fails. I was able to work around the issue by trying a second load with cachePolicy: .returnCacheDataElseLoad if the first load fails. This bug may be similar to #4649

You can check the code in my app for reference: https://github.com/cloudpilot-emu/cpe-shim-ios/blob/master/app/CloudpilotEmu/ViewController.swift

I can prepare a pull request against the iOS shim if you like ๐Ÿ˜

seems relevant to you @khmyznikov

I've debugged a bit more and it seems that setting cachePolicy: .returnCacheDataElseLoad not only allows the load to proceed, but all assets are apparently correctly served by the service worker. So it really looks like the lack of connectivity causing WKWebView to abort early without initialising the worker, and allowing it to load from the cache seems to fix it without any actual cache load.

@DirtyHairy just to confirm, setting that fixed the issue?

@DirtyHairy just to confirm, setting that fixed the issue?

Yeah, indeed, loading with cachePolicy: .returnCacheDataElseLoad fixes the issue, and checking the devtools suggests that nothing is actually loaded from cache if the service worker is installed.

However, I don't do that on first load, but only if the first load fails --- otherwise, if the service worker has not yet installed and my PWA changes sufficiently (i.e. script names changing and old versions being removed from the server) between the app being terminated and being restarted the service worker will never install and the user will be stuck with a broken version in the cache.

Unfortunately, I still get a delay when there is bad network coverage on the first attempt to load.

This issue has been marked as "needs attention ๐Ÿ‘‹" since it has not been triaged for 7 days. Please triage the issue .

This issue has been marked as "needs attention ๐Ÿ‘‹" since it has not been triaged for 7 days. Please triage the issue .

This issue has been marked as "needs attention ๐Ÿ‘‹" since it has not been triaged for 7 days. Please triage the issue .

This issue has been marked as "needs attention ๐Ÿ‘‹" since it has not been triaged for 7 days. Please triage the issue .

This issue has been marked as "needs attention ๐Ÿ‘‹" since it has not been triaged for 7 days. Please triage the issue .

This issue has been marked as "needs attention ๐Ÿ‘‹" since it has not been triaged for 7 days. Please triage the issue .

This issue has been marked as "needs attention ๐Ÿ‘‹" since it has not been triaged for 7 days. Please triage the issue .

This issue has been marked as "needs attention ๐Ÿ‘‹" since it has not been triaged for 7 days. Please triage the issue .

This issue has been marked as "needs attention ๐Ÿ‘‹" since it has not been triaged for 7 days. Please triage the issue .