Closed Bug 1587793 Opened 5 years ago Closed 5 years ago

Add PWA to Home Screen breaks on second tab

Categories

(Firefox for Android Graveyard :: Web Apps (PWAs), defect, P1)

Firefox 68
ARM
Android

Tracking

(firefox-esr68 verified, firefox72 fixed)

RESOLVED FIXED
Firefox 72
Tracking Status
firefox-esr68 --- verified
firefox72 --- fixed

People

(Reporter: jaume, Assigned: marcosc)

References

Details

Attachments

(4 files)

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:69.0) Gecko/20100101 Firefox/69.0

Steps to reproduce:

Close fennec completely and open it again with no tabs for a clean state.
Open any PWA, such as https://platform-status.mozilla.org/
Close the tab.
Open the PWA site again in a new tab.
Press the Add to Home icon (House with a + inside) to add it to your Home.
A modal will open with a bigger "+ ADD TO HOME SCREEN" blue button. Press that button.
You will see that the title is not "Platform Status" as stated in the manifest.json for the PWA but instead the <title> of the page, "Firefox Platform Status". This is the first symptom that the manifest is not being read correctly.
Press ADD AUTOMATICALLY or drag somewhere in the home screen.
When the icon on the home screen is pressed, "Platform Status" will open as a new tab, as if the icon were a mere link.

I have attached a video that shows first the correct behavior (without closing the tab) and then the broken behavior (as described above)

Actual results:

The resulting icon not a proper PWA but a link to open the page, as if it had been generated using:
Three dot menu -> Page -> Add Page Shortcut

Expected results:

The expected results are that the icon has the correct title and opens as a proper app. This behaviour happens when following these steps (same as before, without the tab close):

Close fennec completely and open it again with no tabs for a clean state.
Open any PWA, such as https://platform-status.mozilla.org/
Press the Add to Home icon (House with a + inside) to add it to your Home.
A modal will open with a bigger "+ ADD TO HOME SCREEN" blue button. Press that button.
You will see that the title is "Platform Status" as stated in the manifest.json for the WPA.
Press ADD AUTOMATICALLY or drag somewhere in the home screen.
When the icon on the home screen is pressed, "Platform Status" will open like an App, with no URL bar or browser UI.

The video attachment failed the first time, so I had to reencode it for a smaller file size.

Bugbug thinks this bug should belong to this component, but please revert this change in case of error.

Component: General → Web Apps

I have no idea if Bugbug is right or not in setting the category to Web Apps, but somebody should probably check.

Anyway, I will explain what I have done to try to debug this:

Enable remote debugging over USB
Hook to the Main Process (not the tab)
See that when the bug happens, an error is printed to the console:

Failed to install: messageManager is null browser.js:formatted:1910
    installManifest browser.js:1924
    AsyncFunctionThrow self-hosted:843

Look around the code to find that the manifest object (the one that fails to install) has a property _browser where messageManager is null.

I suspect this _browser object refers to the old tab and is invalid. If getManifest in Manifest.jsm got patched the following way, I think the bug would go away, but I'm not familiar enough with the code to say for sure:

    if (manifestUrl in this.manifestObjs) {
+     this.manifestObjs[manifestUrl]._browser = browser;
      return this.manifestObjs[manifestUrl];
    }

I have recorded a very short video that shows this in the debugger: https://www.youtube.com/watch?v=Ff2nTuFoVU0

I have added the second video as an attachment too.

Hi,
I checked with a Google Pixel 3a XL and Sony Xperia Z 5 (Android 7.0) on Firefox Release 68.1.1 and Firefox Beta 68.2b6 versions from playstore and reproduced the issue.

Note:

Status: UNCONFIRMED → NEW
Ever confirmed: true
OS: Unspecified → Android
Hardware: Unspecified → ARM

Phabricator seems hard to set up, so for now I am attaching the patch I made with mercurial.
I assume _ in "_browser" stands for private and thus modifying the property from outside like this is bad style, but this one line change fixes the bug.

James, do you think we should accept this patch? And if so, can you nominate a reviewer?

Flags: needinfo?(snorp)

Jaume, thank you very much for the thorough investigation and the patch. Fennec is in maintenance mode, but I think this is a trivial fix with high impact so I will find out how we can land this.

Seems like it might be ok to me? I think Marcos maintains this code.

Flags: needinfo?(snorp) → needinfo?(mcaceres)
Severity: normal → minor
Priority: -- → P1

Marcos would you mind helping out with this bug? Do you think this is low risk?

Yes, I can take a look.

Flags: needinfo?(mcaceres)
Assignee: nobody → mcaceres

At some point in the future, we should probably switch the cache to be a WeakMap keyed off the browser objects. I'm worried that the current code keeps copies of browser objects, which are quite expensive. It would probably also catch this kind of bug too.

Ok, yeah... I'm looking at this more and I think we need to refactor all this code... I'll send a patch that should at least address this, but then we need to switch all this to not hold strong references to browser object. My concern is that if one can spin up multiple tabs (3x) each will override the associated browser for a cached manifest (leading to confusion or worst).

Addresses the problem of cached manifests having the wrong associated browser.
However, this is only temporary solution, as cached manifests can have different
associated browsers (e.g., if 3x more tabs are open, this will still potentially be racy).

Pushed by mcaceres@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/ef633bc5dc59
re-associate manifest with a browser when getting them from cache r=snorp
Blocks: 1590978
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 72

Marcos, can you please add a test build in order to verify the fix before will be landed on esr68? Thanks!

Flags: needinfo?(mcaceres)
Flags: needinfo?(mcaceres)

Hi Sorina, tests seem ok but please let me know if I've run all the right things above.

Flags: needinfo?(sorina.florean)

Just a quick shout out to Jaume Delclòs Coll for figuring out where the bug was! Save us a bunch of time figuring this out.

Jaume, if you get a chance to apply the patch, would like to hear if it works ok for you.

Hi Marcos, since fennec is not in mozilla-central anymore, I have applied the patch on top of 55c8e3ba286f (tip of mozilla-esr68 right now) and it seems to work perfectly as far as I have tested.

That's great news, Juame. Thanks so much for checking! Really appreciate it.

Flags: qe-verify?
Flags: qe-verify+
Flags: needinfo?(sorina.florean)

I tested the build from Comment 23 with Pixel 3 XL (Android 9) and the issue no longer occurs.

Flags: qe-verify+
Flags: needinfo?(mcaceres)

Thank you Laurentiu!

I'm unsure now how to "request uplift" to ESR68. Bouncing back to Sorina for guidance.

Flags: needinfo?(mcaceres) → needinfo?(sorina.florean)

Comment on attachment 9102049 [details]
re-associate manifest with a browser when getting them from cache

ESR Uplift Approval Request

  • If this is not a sec:{high,crit} bug, please state case for ESR consideration: The bug affects users who have installed PWAs.
  • User impact if declined: Yes - see the bug for details.
  • Fix Landed on Version: 72
  • Risk to taking this patch: Low
  • Why is the change risky/not risky? (and alternatives if risky): The patch has been QE verified as working as expected. We also checked it on try on the relevant Android builds.
  • String or UUID changes made by this patch: none, I think?
Attachment #9102049 - Flags: approval-mozilla-esr68?

Comment on attachment 9102049 [details]
re-associate manifest with a browser when getting them from cache

Fixes a Fennec PWA regression. Approved for Fennec 68.3b3.

Flags: needinfo?(sorina.florean)
Attachment #9102049 - Flags: approval-mozilla-esr68? → approval-mozilla-esr68+

Hi, verified as fixed with Google Pixel 3 XL (Android 9), Samsung Galaxy S9 (Android 8.0.0) and Sony Xperia Z5 (Android 7.0) on Firefox Beta 68.3b3.
Will leave the ticket with status unchanged until the fix reaches the release version.

I have tested the issue on 68.3.0 RC using a Samsung Galaxy S9 (Android 8.0.0) and the issue no longer occurs. I will mark it accordingly.

Product: Firefox for Android → Firefox for Android Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: