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 progress
40%

Step 1 of 6

Overview

the server, letting you inspect, modify, block, or fully replace the response.

OverviewDrag stickies · tap for tips
Study mapDrag stickies · tap for tipsKeep it shortdrag · tap →Name the waitdrag · tap →Scope locatorsdrag · tap →Trace when stuckdrag · tap →One browser firstdrag · tap →Isolate statedrag · tap →Assert the UIdrag · tap →Retry wiselydrag · tap →Seed datadrag · tap →Close the loopdrag · tap →Keep it shortdrag · tap →Name the waitdrag · tap →Scope locatorsdrag · tap →Trace when stuckdrag · tap →One browser firstdrag · tap →Isolate statedrag · tap →Pathwise hackdrag · tap →Page under testdrag · tap →Multi-browserdrag · tap →Automation pathdrag · tap →Tooling nodedrag · tap →

Try it

Run / study this snippet

page.route() basics
Was 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.