To close popup tabs automatically in Puppeteer, you can listen for each page's popup event and close what it hands you. For a suite that visits many sites, we found a better rule: give every test its own tab, and when the test ends, close every page target you did not open on purpose. That catches the windows no listener saw, and it means one site crashing its renderer costs one test instead of the run.
We learned this from our own detection runner, which checks a browser profile against 49 public detector sites. Somebody watching the window reported it in one line: "all that testing was done in the same chrome instance, it had like 30 tabs".
How one tab turned into thirty
The runner attached to one page when the browser started and navigated that same tab from detector to detector for the whole run. Our code never opened a second tab. The sites did. A captcha demo opens its challenge in a popup, an ad frame opens a window, and nothing ever closed them.
By the end of a run the browser was holding a few dozen live tabs, every one still running its timers and holding a renderer. That is worse than untidy for a suite whose job is to say what a site sees, because no real profile is ever in that state. The harness had become part of what it measured.
The run that died at test three
Then one run lost its page target three tests in. Our check for a dead connection watched the WebSocket, and the socket was fine. Only the target had gone. So the loop went on through the other 46 detectors, each one failing with Session with given id not found, and wrote a report from 3 real rows and 46 errors over a report that had 35 passes in it.
Two fixes came out of that. A run that is mostly errors no longer writes the report at all, since a file full of exceptions describes a bug in the runner rather than the profile. And every test got its own tab.
Everything the window does, from a script on your own computerIn Mosaic: REST API. Everything the window does, from your own scripts. Free covers 3 profiles with no card, and Pro is $25 a month for any number of them.
Mosaic is a desktop app
Email yourself the link and open it on your computer.
A fresh tab per test, swept at the end
Our runner talks to the browser over the Chrome DevTools Protocol directly rather than through Puppeteer, because Puppeteer and Playwright both enable the Runtime domain when they attach, and we measured that flipping a detector to a bot verdict (the measurement is here). The shape works in either, though. Per test it does this:
- Create a blank tab with
Target.createTarget, attach to it, and navigate it to the detector. - Run the test and read the verdict.
- List every target with
Target.getTargets. - Close every
pagetarget that is not on the keep list, withTarget.closeTarget.
The keep list has two entries, both named when they are created: the tab the browser started with, because a browser with no tabs quits, and a blank scratch tab that reads the IP address without depending on the site's own security policy. Anything else alive at the end of a test arrived during it, so it belongs to the site and is closed. The runner logs when it closes more than one, which is how we can see which detectors open windows.
In Puppeteer terms, that is browser.newPage() per test, then browser.pages() at the end and page.close() on everything that is not one of yours. A popup listener can still be useful on top, but the sweep is the part that cannot miss.
What the count looked like afterwards
We polled the profile's own DevTools endpoint 145 times across a full run. Every sample had exactly three page targets: the startup tab, the scratch tab, and the tab under test.
The results moved too. Same profile, same proxy, same engine, with only the tab handling changed:
shared tab, run 1 33 pass 1 fail 5 unreachable 1 unread
shared tab, run 2 35 pass 1 fail 2 unreachable 1 error
shared tab, run 3 1 pass 46 error (the session died at test 3)
own tab per test 37 pass 0 fail 1 unreachable
Pixelscan agreed on a pass across three rounds afterwards, where it had agreed on a fail across three rounds before. We do not claim the tabs caused that, because the proxy's IP moved between those runs as well, and a change that moves two things proves neither. What it does show is that measurements taken through the old harness are not worth trusting.
A new tab also has to be the front tab
The fix had a side effect we found later. The scratch tab was created after the test tab, and the newer target is the active one, so every test ran in a background tab. Chromium does not run requestAnimationFrame there and holds setTimeout to about one call a second. Two detectors that share one slow fingerprint collector never finished and sat at "unread" for weeks.
The runner now calls Page.bringToFront on the test tab before every navigation, rather than relying on the order tabs were created in, because anything that opens a tab later would undo an ordering fix. The full story of that one is in the detector that never answered because its tab was in the background, and the list of sites the runner visits is our 49 detectors.






