- Note that this repro just compares waitForSelector performance. This alone does NOT mean "Puppeteer is faster in general"
- GitHub issue in Playwright: microsoft/playwright#24578
Since Puppeteer is internally using polling: 'mutation'
option in waitForFunction
for waitForSelector
, it will use MutationObserver to efficiently react to newly appeared DOM node.
On the other hand, Playwright removed polling: 'mutation'
completely in this PR and its waitForSelector
is purely relying on repeated retries on the hardcoded intervals here.
This repro has minimal demo to reproduce the performance difference caused by this implementation difference.
Please check out ./main.js
to see what is benchmarked first.
npm ci
npm run puppeteer
npm run playwright
I ran the above on my MacBook Air (M2) and the result was the following:
puppeteer: It took 10ms to react to the appearance of <a> element
playwright: It took 321ms to react to the appearance of <a> element
So Puppeteer has more than 20x faster waitForSelector
compared with the one from Playwright.