playwright request interception slowing tests: how to speed up
Speeds up Playwright suites slowed down by page.route() handlers. Use when interception adds seconds per test. Not for slowness coming from the app itself.
TL;DR
Every intercepted request pays handler overhead, so narrow the URL pattern until most traffic passes through untouched, abort blocked assets instead of fulfilling them, and only enable interception in the specs that need it.
The query
playwright request interception slowing tests: how to speed upUse this when
- page.route() noticeably slows the suite
- catch-all patterns intercept every request
- CI time crept up after adding mocks
Not for
- slow app responses
- slow selectors
- parallel-worker tuning
Steps
- Time a spec with and without the route handlers to measure the interception cost. Expected output: a timing comparison showing how much the handlers add.
- Narrow each pattern from catch-alls to the specific paths under test, like '*/api/search'. Expected output: unrelated requests no longer enter the handler.
- For blocked assets such as fonts or analytics, call route.abort() instead of fulfilling with a fake body. Expected output: blocked requests fail fast.
- Move interception setup into the specs that need it instead of a global fixture. Expected output: specs without interception run at full speed.
- Re-run the suite and confirm the timing improvement with no new flakes. Expected output: a faster suite with the same pass rate.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst7kzrSwYib0asJ5sJ8PVlQ
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.