Manuals / Playwright with Python / Chapter 25
Part 4 · Advanced Techniques · advanced · ~50 min · Chapter 25 of 61
17. Network Interception & Mocking
page.route() basics page.route() intercepts network requests matching a URL pattern before they reach the server, letting you inspect, modify, block, or fully replace the response. def handle_route(route): route.continue_() # let it through unchanged page.route("**/*.png", handle_route) page.route(url_pattern, handler) What it does: Registers an interceptor for any request matching a URL pattern.
Path progress40%
Step 1 of 6
Overview
the server, letting you inspect, modify, block, or fully replace the response.
Try it
Run / study this snippet
page.route() basicsWas this step clear?
Chapter learning outcomes
- Mocking API responses
- 500 for error-state testing
- Blocking resources (images, ads) for speed
Clear these before you leave
Side quest
17. Network Interception & Mocking deliverable
Apply one idea from “Overview” in a small script or note.