GithubHelp home page GithubHelp logo

ios-pwa-freeze-bug's Introduction

PWAs on iOS Freeze While Multitasking

If you use Service Workers on PWAs on iOS 13.x, your app will freeze when multitasking.

The Issue

The underlying issue appears to be a race condition in the PWA container. Whenever you switch off your PWA into some other app, your page JavaScript context and Service Worker JavaScript context have a very brief grace period to execute before iOS pauses your app. Normally, these contexts will be restored when your app becomes visible, but if you use Service Workers, sometimes the contexts don't get restored.

I have not been able to reproduce this without the presence of a Service Worker.

Reproducing

This repository contains just enough to reproduce the issue, albeit unreliably. You need to host these files on a server supporting HTTPS so that the Service Worker can be registered in the first place, then:

  1. Navigate to ./jsclock.html
  2. Add the app to your home screen
  3. Close the tab in Mobile Safari
  4. Open the app from the home screen
  5. Swipe between this app and others a few times. Eventually, the clock will freeze.

Getting More Information

This is a very noisy app in terms of console logging. You should establish a Remote Debugging session for both the page context and the Service Worker:

Choosing Sources

You should see the Service Worker logging once a second. If you switch apps or go back to the Home Screen, you will see something like this:

Console When Switching

You will reliably see the log message Document visibility changed - true, which means that the freezing does not occur while suspending the app. It occurs when attempting to resume the app.

The Service Worker will begin logging at an interval of 16ms when the visibilty status of the app becomes hidden. That will look something like this:

Service Worker When Switching

However, I could not determine any correlations between timing and this bug, at least from the standpoint of a JavaScript execution context.

This issue is easiest to trigger after the first start of the app. In this reproduction, it's very difficult to reproduce more than once while the app is running.

Items of Interest, Not Reproduced Here

This issue was discovered by multiple users of Glide, which allows anyone to create amazing Progressive Web Apps without code. While debugging this issue in the context of Glide, we noticed some of the following:

  1. You can pause JavaScript execution in the page itself and still freeze the Service Worker by multitasking, so this problem has nothing to do with the JavaScript we are executing.
  2. Scrolling does not work on overflow: scroll divs when this happens, but normal overflow scrolling seems to work.

ios-pwa-freeze-bug's People

Contributors

djsweet avatar

Stargazers

 avatar Amirhossein Mirkazemi avatar

Watchers

 avatar  avatar

Forkers

glideapps

ios-pwa-freeze-bug's Issues

Add images to README

Dear Github,

Why can't I just upload images straight in the README editor? Why must I hack around this limitation by opening an issue?

Choosing the remote debugging sources:

Remote Debug Sources

Console when switching:

Console When Switching

Service worker when switching:

Service Worker When Switching

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.