web icon indicating copy to clipboard operation
web copied to clipboard

visual regression `visualDiff` hangs forever when tab is in background

Open melink14 opened this issue 1 year ago • 5 comments

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...)

melink14 avatar Dec 18 '24 03:12 melink14

(A similar problem for .click was opened on puppeteer: https://github.com/puppeteer/puppeteer/issues/5201)

melink14 avatar Dec 19 '24 09:12 melink14

Any update on this?

melink14 avatar Jan 29 '25 09:01 melink14

I tested this again and it's still a problem. Prevents running tests concurrently.

melink14 avatar May 13 '25 07:05 melink14

Would a PR be accepted?

melink14 avatar Jun 13 '25 07:06 melink14

@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?

bashmish avatar Jun 16 '25 08:06 bashmish