visual regression `visualDiff` hangs forever when tab is in background
With new headless chrome (and headfull), if the tab is in the background takeScreenshot never returns (and no timeouts fire until the top level 120s timer fires;)
This is because element.screenshot in puppeteer relies on IntersectionObserver (via scrollIntoViewIfAble) doesn't work in backgrounded tabs. (ref: https://github.com/puppeteer/puppeteer/blob/682bb682116437dc803afd613eb95fd2efd65a65/packages/puppeteer-core/src/api/ElementHandle.ts#L1479)
I made a local patch where I just added page.bringToFront() before calling element.screenshot and that seems to work though I'm not sure if there's a better fix. (ref: https://github.com/modernweb-dev/web/blob/17cfc0d70f46b321912e4506b2cccae1b16b1534/packages/test-runner-visual-regression/src/visualRegressionPlugin.ts#L79)
It seems like when the simlar https://github.com/modernweb-dev/web/pull/2366 was merged it added a __bringTabToFront method to window which I could call before visualDiff as well but it seems like an implementation detail I shouldn't rely on.
For now, I can use patch-package but I'd love to hear thoughts on this approach.
For completeness, similar to other new headless bugs, this can be fixed by setting concurrency to 1 as well.
(As an aside, given we patched requestAnimationFrame I wonder if we should also patch client side IntersectionObserver to call bringTabToFront...)
(A similar problem for .click was opened on puppeteer: https://github.com/puppeteer/puppeteer/issues/5201)
Any update on this?
I tested this again and it's still a problem. Prevents running tests concurrently.
Would a PR be accepted?
@melink14 PR is very welcome, I can look into it! However I can't find tests of this functionality on our side, so I think a simple fix is not enough. Will you be able to write tests also, especially targeting the scenario that you are fixing?