<p dir="auto">It seems that <code class="notranslate">document.hidden</code> is not working once the browser is controlled by Playwright.</p>
<p dir="auto">Given you open a browser tab (outside of playwright) and inject in the console the script :</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="setInterval(() =&gt; {console.log(`document.hidden = ${document.hidden}`)}, 1000)"><pre class="notranslate"><span class="pl-en">setInterval</span><span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span><span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">`document.hidden = <span class="pl-s1"><span class="pl-kos">${</span><span class="pl-smi">document</span><span class="pl-kos">.</span><span class="pl-c1">hidden</span><span class="pl-kos">}</span></span>`</span><span class="pl-kos">)</span><span class="pl-kos">}</span><span class="pl-kos">,</span> <span class="pl-c1">1000</span><span class="pl-kos">)</span></pre></div>
<p dir="auto">When you open a new browser tab<br>
And you wait a few seconds<br>
And you come back to the previous tab<br>
Then you have the following logs in the console:</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/9698924/153960323-cc3926de-360f-495f-8131-de4c13768983.png"><img src="https://user-images.githubusercontent.com/9698924/153960323-cc3926de-360f-495f-8131-de4c13768983.png" alt="Screen Shot 2022-02-14 at 23 51 53" style="max-width: 100%;"></a></p>
<p dir="auto">When you do the same steps in a browser controlled by Playwright<br>
Then you have the following logs in the console :<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/9698924/153961181-d88ee59d-cf26-4cdb-8c08-95998750a31f.png"><img src="https://user-images.githubusercontent.com/9698924/153961181-d88ee59d-cf26-4cdb-8c08-95998750a31f.png" alt="Screen Shot 2022-02-15 at 00 00 38" style="max-width: 100%;"></a></p>
<p dir="auto">Unless I am wrong, <code class="notranslate">document.hidden</code> should be handled by Playwright.<br>
This missing feature prevents to test the front stops specific activities (for example the front stops to poll a rest API endpoint) when the user switches from one browser tab to another, and vice-versa: the front should, for example, restart it's polling activity when the browser tab becomes actif again.</p>
<p dir="auto">Regards</p>
<p dir="auto">Presently Playwright treats all tabs as active. This can become an issue when a tab we're not currently focusing on is running a lot of work.<br>
I'll use the site MakeUseOf.com as an example. When this tab is active, it can consume 25-30% CPU time on my brand new MBPro. Under normal Chromium, when the tab is not the current tab Chromium will throttle timers (and whatever else it may do) and the site will settle around 2% CPU.<br>
Under Playwright, this inactive tab will continue to use full resources (25-30% CPU).</p>
<p dir="auto">I'd like to see a flag or an API call (<code class="notranslate">page.goToBack()</code> was suggested) that would allow inactive tabs to sleep.</p>
<p dir="auto">Here's a link to the <a href="https://playwright.slack.com/archives/CSUHZPVLM/p1597965643016100" rel="nofollow">original discussion</a>.</p>
<p dir="auto">Thanks!</p>