How to fix content rendering stopping when the browser window is inactive, for example, broadcast via Google Meet and at that moment minimized

7,906 views
Skip to first unread message

Viacheslav Voronko

unread,
May 15, 2024, 1:08:38 PM5/15/24
to Chromium-dev
The video first shows the working behavior when performance.now() is updated on the page and after 5 seconds a transition to another page is performed. Why is the part of the javascript that is used to navigate to another page executed, but the part that is responsible for outputting performance.now() is not displayed in Google Meet (when the browser window is inactive)?

code from video

index.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h3>index.html LOADED</h3>
    <h3 id="test"></h3>

    <script>
        setTimeout(()=>{
            console.log("Change location")
            location.href = "./index2.html"
        }, 5000)

        function step(timestamp) {
           
            document.querySelector('#test').textContent =  performance.now()
           
            window.requestAnimationFrame(step);
        }

        window.requestAnimationFrame(step);

    </script>
</body>
</html>

index2.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h3>index.html2 LOADED</h3>
    <h3 id="test"></h3>

    <script>
        setTimeout(()=>{
            console.log("Change location")
            location.href = "./index.html"
        }, 5000)

        function step(timestamp) {
           
            document.querySelector('#test').textContent =  performance.now()
           
            window.requestAnimationFrame(step);
        }

        window.requestAnimationFrame(step);
    </script>
</body>
</html>

20240508141827.mp4

Joe Mason

unread,
May 15, 2024, 6:18:39 PM5/15/24
to ungl...@gmail.com, Chromium-dev
requestAnimationFrame() is paused when tabs are hidden, since it's assumed that any animation frames won't be displayed so there's no point doing work rendering them. (See https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame - "requestAnimationFrame() calls are paused in most browsers when running in background tabs or hidden <iframe>s, in order to improve performance and battery life.")

Arguably the tab should NOT be considered hidden when it's being captured for screencasting. I don't know enough about it to say why that's not happening in your test - if you think this is a bug, please file it at https://issues.chromium.org/new and attach this test case.

Pretty much all I remember from last time I looked at this is that WebContentsImpl::IncrementCapturerCount() should be tracking whether the page is being captured (https://source.chromium.org/chromium/chromium/src/+/main:content/browser/web_contents/web_contents_impl.cc;l=2344;drc=7e088bf159ef779ea494dd55bb48916be569b06a), and there are a lot of confusing rules about how this interacts with visibility.

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/0090d4d8-2fc0-4b66-a435-87d568921d67n%40chromium.org.

guest271314

unread,
May 15, 2024, 9:20:47 PM5/15/24
to Chromium-dev, Joe Mason, Chromium-dev, ungl...@gmail.com
I'm not sure the HTML reflects what you are trying to do relevant to getDisplayMedia(). Can you describe in detail this part

>  but the part that is responsible for outputting performance.now() is not displayed in Google Meet (when the browser window is inactive)?

There are various ways to keep a tab or window active persistently. One way is using a ServiceWorker to exchange messages between ServiceWorker and WindowClient.

guest271314

unread,
May 16, 2024, 10:18:38 AM5/16/24
to Viacheslav Voronko, Chromium-dev, Joe Mason
Sure https://github.com/guest271314/persistent-serviceworker.

1. Make sure Memory Saver is off in Settings.
2. Technically this can be done using BroadcastChannel as well.

On Thu, May 16, 2024 at 2:09 AM Viacheslav Voronko <ungl...@gmail.com> wrote:
There are various ways to keep a tab or window active persistently. One way is using a ServiceWorker to exchange messages between ServiceWorker and WindowClient.
thank you, could you elaborate a little more on this. I think making the window permanently visible should solve my problem
четверг, 16 мая 2024 г. в 04:20:47 UTC+3, guest271314:

Viacheslav Voronko

unread,
May 16, 2024, 1:56:50 PM5/16/24
to Chromium-dev, guest271314, Joe Mason, Chromium-dev, ungl...@gmail.com
There are various ways to keep a tab or window active persistently. One way is using a ServiceWorker to exchange messages between ServiceWorker and WindowClient.
thank you, could you elaborate a little more on this. I think making the window permanently visible should solve my problem
четверг, 16 мая 2024 г. в 04:20:47 UTC+3, guest271314:
I'm not sure the HTML reflects what you are trying to do relevant to getDisplayMedia(). Can you describe in detail this part
Reply all
Reply to author
Forward
0 new messages