Page Visibility API

1,120 views
Skip to first unread message

Luís Medeiros

unread,
Oct 3, 2016, 1:17:04 PM10/3/16
to android-webview-dev
Hi guys!

I'm trying to use Page Visibility API in a Android WebView (v. 54.0.2840.42), but I've got some problems.

For example, a detached WebView always returns visibilityState = 'visible'. (It's not make sense! The WebView isn't attached to window, how could it be visible?!).
And a focused WebView returns visibilityState = 'visible' even when screen is turned off.

However, in some cases the WebView works. For example when the app is switched for another and it goes to background, the backgrounded WebView rightly returns visibilityState = 'hidden'.

So, can anybody explain something about these wrong behaviors? 

Bests,

Bo Liu

unread,
Oct 3, 2016, 1:26:00 PM10/3/16
to Luís Medeiros, android-webview-dev
Yeah that behavior looks odd, but it's intended. Visibility is calculated as:

visible = !paused && (!attached to window || window visible) 

In other words, the window visible state is ignored if webview is detached. This is because webview does not know the window visibility state when it is detached, and there are many apps that uses a detached webview when detached, so expects a detached webview to function normally as if it's visible.

Another "oddity" you didn't notice is page visibilityState has nothing to do with WebView.setVisibility

If you want to control page visibility from your app, use WebView.onPause/onResume.

--
You received this message because you are subscribed to the Google Groups "android-webview-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-webview-dev+unsub...@chromium.org.
To post to this group, send email to android-webview-dev@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/android-webview-dev/278b9832-e43e-4af3-8919-3f7d1df81967%40chromium.org.

Luís Medeiros

unread,
Oct 3, 2016, 1:43:20 PM10/3/16
to android-webview-dev, lpmf...@gmail.com, bo...@chromium.org
Hi, Bo!

Unfortunately these behaviors don't compliant with my expectations...

I need to handle the visibility state of a WebView from the javascript code and I believed that I could it thought Page Visibility API.

Thank you anyway.


On Monday, October 3, 2016 at 2:26:00 PM UTC-3, Bo Liu wrote:
Yeah that behavior looks odd, but it's intended. Visibility is calculated as:

visible = !paused && (!attached to window || window visible) 

In other words, the window visible state is ignored if webview is detached. This is because webview does not know the window visibility state when it is detached, and there are many apps that uses a detached webview when detached, so expects a detached webview to function normally as if it's visible.

Another "oddity" you didn't notice is page visibilityState has nothing to do with WebView.setVisibility

If you want to control page visibility from your app, use WebView.onPause/onResume.
On Mon, Oct 3, 2016 at 10:17 AM, Luís Medeiros <lpmf...@gmail.com> wrote:
Hi guys!

I'm trying to use Page Visibility API in a Android WebView (v. 54.0.2840.42), but I've got some problems.

For example, a detached WebView always returns visibilityState = 'visible'. (It's not make sense! The WebView isn't attached to window, how could it be visible?!).
And a focused WebView returns visibilityState = 'visible' even when screen is turned off.

However, in some cases the WebView works. For example when the app is switched for another and it goes to background, the backgrounded WebView rightly returns visibilityState = 'hidden'.

So, can anybody explain something about these wrong behaviors? 

Bests,

--
You received this message because you are subscribed to the Google Groups "android-webview-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-webview-dev+unsub...@chromium.org.
To post to this group, send email to android-w...@chromium.org.

Selim Gurun

unread,
Oct 3, 2016, 1:51:18 PM10/3/16
to Luís Medeiros, android-webview-dev, Bo Liu
if this is for a custom application where you own both js and java, then can't you inject the visibility from java side?

On Mon, Oct 3, 2016 at 10:43 AM, Luís Medeiros <lpmf...@gmail.com> wrote:
Hi, Bo!

Unfortunately these behaviors don't compliant with my expectations...

I need to handle the visibility state of a WebView from the javascript code and I believed that I could it thought Page Visibility API.

Thank you anyway.

On Monday, October 3, 2016 at 2:26:00 PM UTC-3, Bo Liu wrote:
Yeah that behavior looks odd, but it's intended. Visibility is calculated as:

visible = !paused && (!attached to window || window visible) 

In other words, the window visible state is ignored if webview is detached. This is because webview does not know the window visibility state when it is detached, and there are many apps that uses a detached webview when detached, so expects a detached webview to function normally as if it's visible.

Another "oddity" you didn't notice is page visibilityState has nothing to do with WebView.setVisibility

If you want to control page visibility from your app, use WebView.onPause/onResume.
On Mon, Oct 3, 2016 at 10:17 AM, Luís Medeiros <lpmf...@gmail.com> wrote:
Hi guys!

I'm trying to use Page Visibility API in a Android WebView (v. 54.0.2840.42), but I've got some problems.

For example, a detached WebView always returns visibilityState = 'visible'. (It's not make sense! The WebView isn't attached to window, how could it be visible?!).
And a focused WebView returns visibilityState = 'visible' even when screen is turned off.

However, in some cases the WebView works. For example when the app is switched for another and it goes to background, the backgrounded WebView rightly returns visibilityState = 'hidden'.

So, can anybody explain something about these wrong behaviors? 

Bests,

--
You received this message because you are subscribed to the Google Groups "android-webview-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-webview-dev+unsubscribe...@chromium.org.

--
You received this message because you are subscribed to the Google Groups "android-webview-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-webview-dev+unsub...@chromium.org.

Luís Medeiros

unread,
Oct 3, 2016, 2:37:28 PM10/3/16
to Selim Gurun, android-webview-dev, Bo Liu
No, it is not for a own application.

My scenario is: I need deliver a html+js code to third apps that will load it in WebViews, and this js needs to handle the visibility state of WebView to dispatch actions on html.

To post to this group, send email to android-webview-dev@chromium.org.




--
Luís Medeiros

Torne (Richard Coles)

unread,
Oct 4, 2016, 9:01:01 AM10/4/16
to Luís Medeiros, Selim Gurun, android-webview-dev, Bo Liu
The page visibility API is not intended to be 100% accurate. It's intended for purposes like pausing animations when the user can't possibly be seeing them. If you read the spec, the wording is pretty specific: the browser is expected to return "visible" except when it knows that the page is definitely not visible. For example, on desktop systems, a browser window that's completely covered up by other windows will typically report that it's visible, because the way most modern desktops composite windows mean that this isn't possible to determine.

So, WebView behaves similarly: when we can't be sure if we're visible or not (such as when not attached to a view hierarchy) we return visible, because if we always treat "not attached" as invisible, then apps which render the webview while it's not attached to the view hierarchy will show pages in incorrect states.

What's your actual use case for the visibility API here? If it's not "as an optimisation to avoid doing unnecessary work" then you might be looking for something else..

To unsubscribe from this group and stop receiving emails from it, send an email to android-webview...@chromium.org.

--
You received this message because you are subscribed to the Google Groups "android-webview-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-webview...@chromium.org.

To post to this group, send email to android-w...@chromium.org.




--
Luís Medeiros

--
You received this message because you are subscribed to the Google Groups "android-webview-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-webview...@chromium.org.

To post to this group, send email to android-w...@chromium.org.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages