Live data from Hacker News

Quirks of the Page Visibility API

mattj.io

11–20 of 22 posts

Re: Quirks of the Page Visibility API

#11
post #9

Earlier quoted context omitted.

> The blanket "yes/no" setting isn't nearly enough for these kinds of things. why not? These are all things the current underlying implementation checks for, and report via the visibility api, which is just a boolean effectively. The user should be able to set a toggle, where the visibility api will return "true" (aka visible), for all of these underlying checks that the browser does. E.g., the visibilityChange event…

> why not? Because some of them are harmless, some of them are less harmless. Same goes for all the other APIs that require user permissions. In the end the user will just click "yes" on all of them. > The user should be able to set a toggle, where the visibility api will return "true" (aka visible), for all of these underlying checks that the browser does. Does the user know what those checks are? Did you know which…

> For example, a well-meaning website performing intensive computation only when the page is visible.

if the user wants the computation to continue, despite being not visible, the site should not be able to override it. It would be anti-user otherwise.

often, i would see video sites _not_ prebuffering when the page is not visible. Or, deliberately switch over to a low resolution version of the video when the visibility changes - twitch does that. Even if i have the video overlay playing outside the browser window (so technically, it is visible, just not according to the API).

Essentially, if the user has the know how to switch this preference (and it would be per site, or even per session, like mic or camera), they would know the consequences.

> require user permissions.

It's not a permission per se, but a toggle, so the user might turn it on or off depending on their circumstances. They don't need to understand it - they can just leave it on default as what the browser currently does if they don't understand, or don't have any problems with the site's behaviour.

Re: Quirks of the Page Visibility API

#13
post #4

There are still very few addons you can install on Firefox for Android (without a dev version and a bunch of hassle), but it's telling that one of the few addons that anyone can install disables this API: https://addons.mozilla.org/android/addon/video-background-pl...

I recently learned that uBlock Origin can block that API, too.

https://news.ycombinator.com/item?id=33997228

Re: Quirks of the Page Visibility API

#16

It might make sense to detect page visibility prior to loading a pay-per-load API like Mapbox GL JS, Apple Maps on Web, etc. The scenario I imagine is: 1. Your map is loaded 2. User opens a new tab (your map is now in a background tab) 3. User restarts browser and existing tabs are loaded 4. You get charged for an API load even though the page is not visible Does anyone know if this is the case? Edit: also analytics.…

Seems like a good use case. I wrote a Christmas quiz app in December and I could see from the server logs someone must have left the scoreboard page open for weeks as I used polling to check for the latest score. Checking if the tab was even active would have been a good idea.

Re: Quirks of the Page Visibility API

#17
post #5
post #2

IIRC this comes down to disagreements between browser vendors as to what is and what isn't potentially harmful (for a wide definition of harmful) detection of user behavior. I don't remember the details, but expect browsers to differ on details of this API basically forever.

Why isn't the user in charge of whether they want the page visibility api to report them?

An inscrutable power-user feature to appease some privacy purist nerds, all while the 99.999% leaves it set to the default behaviour and gets screwed by ad companies. That’s not fighting for privacy, it’s copping out.

Re: Quirks of the Page Visibility API

#20
I tried using the page visibility API to refresh displayed data when the user returned to the page after being away for a while. It's more efficient than needlessly polling when no one's around to see.

I discovered a bunch of these edge cases and had to abandon the approach - it just wasn't reliable. The page would fail to recognize departure + return in too many scenarios and so wouldn't refresh.

Post reply on HN