Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visibility API is not working after window.open in Chrome

I was trying to use Visibility API, but it is not working for a child. The minimal example to reproduce:

<script>

document.onvisibilitychange = () => {
      console.log(document.visibilityState);
    }

if (!window.opener) {
    window.open(window.location.href, '_blank');
}

</script>

After that, the parent window still prints "visible"-"hidden", but child prints "hidden" once only on refresh.

It works fine in the latest Opera browser, but not in the Chrome

To be honest, when I came to this minimal reproduce, I'm stuck and have no idea where to dig. Any ideas what could be wrong?

like image 553
A. Yushchenko Avatar asked Aug 05 '20 11:08

A. Yushchenko


People also ask

How can Page Visibility API be useful?

Note: The Page Visibility API is especially useful for saving resources and improving performance by letting a page avoid performing unnecessary tasks when the document isn't visible.

What is visibility change?

The visibilitychange event is fired at the document when the contents of its tab have become visible or have been hidden. The event is not cancelable.


1 Answers

I also stumbled over this issue. I think that this bug was introduced in Chrome 84. I testet it with version 83 and it worked as expected. The current Canary-Build (Version 86) is also working.

like image 111
Alex Avatar answered Nov 15 '22 01:11

Alex