Playwright: [Feature] Allow inactive tabs to be backgrounded

Created on 22 Aug 2020  路  1Comment  路  Source: microsoft/playwright

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.
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.
Under Playwright, this inactive tab will continue to use full resources (25-30% CPU).

I'd like to see a flag or an API call (page.goToBack() was suggested) that would allow inactive tabs to sleep.

Here's a link to the original discussion.

Thanks!

P3-collecting-feedback

Most helpful comment

Hi @maustin, just adding a use case that鈥檚 blocked by the same behaviour:

I鈥檓 using Playwright to test a site that uses React Query, and I鈥檓 specifically testing the behaviour where reactivating/refocusing a tab causes data to be refetched (I have two tabs open in the test and am switching between them).

When using chromium, my call to await page.bringToFront() brings the tab into view, but doesn't trigger the data refetching (my understanding from your description is that chromium never considered the tab to be 'background', so reactivating it doesn't change anything). In Firefox the refocusing + refetching behaviour works as expected (although it does it with two windows rather than tabs).

I think testing behaviour like this is a great use of Playwright so it would be wonderful to have the option to ask chromium to behave similarly.

PS The React Query code is specifically responding to both 'visibilitychange' and 'focus' events on the window to trigger its refetching.

>All comments

Hi @maustin, just adding a use case that鈥檚 blocked by the same behaviour:

I鈥檓 using Playwright to test a site that uses React Query, and I鈥檓 specifically testing the behaviour where reactivating/refocusing a tab causes data to be refetched (I have two tabs open in the test and am switching between them).

When using chromium, my call to await page.bringToFront() brings the tab into view, but doesn't trigger the data refetching (my understanding from your description is that chromium never considered the tab to be 'background', so reactivating it doesn't change anything). In Firefox the refocusing + refetching behaviour works as expected (although it does it with two windows rather than tabs).

I think testing behaviour like this is a great use of Playwright so it would be wonderful to have the option to ask chromium to behave similarly.

PS The React Query code is specifically responding to both 'visibilitychange' and 'focus' events on the window to trigger its refetching.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shirshak55 picture shirshak55  路  3Comments

kblok picture kblok  路  3Comments

VikramTiwari picture VikramTiwari  路  4Comments

myobie picture myobie  路  3Comments

juliomatcom picture juliomatcom  路  3Comments