Open Bug 1678103 Opened 5 years ago Updated 1 year ago

[Bug] Incorrect values of document.hidden/document.visibilityState when page is loaded in background tab

Categories

(Firefox for Android :: Tabs, defect)

Unspecified
Android
defect

Tracking

()

Tracking Status
firefox122 --- affected

People

(Reporter: ekager, Unassigned, NeedInfo)

References

Details

(Whiteboard: [geckoview:m86] [geckoview:2022h2?])

Attachments

(1 file, 1 obsolete file)

From github: https://github.com/mozilla-mobile/fenix/issues/16637.

Steps to reproduce

  1. Open https://jg-testpage.netlify.app/document.hidden/landing/
  2. Long press the link on the page and open the link in the new tab.
  3. Wait a few seconds. Switch to the newly opened tab

Expected behavior

The logs until the time when the tab became active should be saying

document.hidden = true; document.visibilityState = hidden;

Actual behavior

The logs are saying

document.hidden = false; document.visibilityState = visible;

In other words, initial values for visibility APIs are wrong when page is loaded as background tab.

Fix

  • The browser should detect that the page is initially invisible
  • and raise visibilitychange once it becomes visible.

(The visibility APIs seem to work correctly when visible page gets changes to invisible (by switching tab) or by minimizing the browser.)

Device information

  • Android device: Huawei P20 lite, Android 9
  • Fenix version: 82.1.3

Change performed by the Move to Bugzilla add-on.

Just a note, the feature works correctly on desktop (tested on Windows); also it works correctly on Android in all Chromium-based browsers I tested.

Scope of the bug is only Firefox Android.

Priority: -- → P2
Whiteboard: [geckoview:m86]
Severity: -- → S3

I just checked and I can still reproduce this in the latest Fenix nightly.

Whiteboard: [geckoview:m86] → [geckoview:m86] [geckoview:2022h2?]

Visibility API is broken in GeckoView. The bug has a minimal test case that can reproduce the bug.

Does this happen still? I think Geckoview/Fenix was fixed (I just can't find now the right bug).

Flags: needinfo?(cpeterson)

It is still a problem, yes

Actually, Testing this in GVE - does not reproduce. Haven't tested on Fenix yet, but I would imagine this should work

In Fenix this is still a problem

Priority: P2 → --
Product: GeckoView → Fenix

A bit more information:

When we tried reproducing it in GVE and Fenix using dev tools (meaning, to navigate by inspecting a background tab) - it doesn't reproduce in Fenix either. So, speculating here, it might have to do with the way a new tab is opened in the background.

I moved this to the Fenix component, but I think to really check which layer this bug is in, might be useful to try to reproduce in another GV powered browser that has ability to pen tabs in background - maybe the Reference Browser. If the state of the tab is not handled correctly by the app - and we don't communicate to Gecko correctly re: the backgroundness of the tab, that might mess up the web APIs

I can still reproduce this bug in Fenix (122) but not in Chrome 121.

Flags: needinfo?(cpeterson)

Over on bug 1877469 comment 8 I mentioned the same problem for the TestRunner application, which is basically used for all the wpt tests. That one is failing as well, whereby tests have shown that both Fenix and GeckoView example are working fine. At the moment it's blocking me to land a patch this reduces races when switching tabs. Owlish maybe you could have a look? Thanks.

Flags: needinfo?(bugzeeeeee)
See Also: → 1877469

I remembered an odd bug I reported in bug 1847566.

Not sure if it is related in any way, but it has a parallel feel to this one, and calls around setFocused and setActive might be a place to investigate. That bug had differing behavior in GVE and Fenix. Additionally, the bug reproduced by switching tabs and touching content a certain way. For example, touching content v. not touching the content when switching tabs caused different behavior with primary = true and primary = false on the browser.

Edit: I have reproduced in Fenix Nightly 123.0a1 and Reference Browser having the wrong initial state of document.hidden = false; document.visibilityState = visible; when opening the tab in the background through a deep click. Didn't try inspecting GVE.

Attachment #9380214 - Attachment mime type: text/plain → text/html
See Also: → 1880376
Attachment #9385439 - Attachment is obsolete: true
Component: General → Tabs
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: