@@ -560,7 +560,7 @@ async def handle(route, request):
560560 \" foo\" : \" bar\" # set \" foo\" header
561561 \" origin\" : None # remove \" origin\" header
562562 }
563- await route.continue (headers=headers)
563+ await route.continue_ (headers=headers)
564564 }
565565 await page.route(\" **/*\" , handle)
566566 ```
@@ -6384,6 +6384,18 @@ async def route(
63846384 await browser.close()
63856385 ```
63866386
6387+ It is possible to examine the request to decide the route action. For example, mocking all requests that contain some
6388+ post data, and leaving all other requests as is:
6389+
6390+ ```py
6391+ def handle_route(route):
6392+ if (\" my-string\" in route.request.post_data)
6393+ route.fulfill(body=\" mocked-data\" )
6394+ else
6395+ route.continue_()
6396+ await page.route(\" /api/**\" , handle_route)
6397+ ```
6398+
63876399 Page routes take precedence over browser context routes (set up with `browser_context.route()`) when request
63886400 matches both handlers.
63896401
@@ -7865,13 +7877,15 @@ def expect_request(
78657877 ) -> AsyncEventContextManager ["Request" ]:
78667878 """Page.expect_request
78677879
7868- Waits for the matching request and returns it.
7880+ Waits for the matching request and returns it. See [waiting for event](./events.md#waiting-for-event) for more details
7881+ about events.
78697882
78707883 ```py
78717884 async with page.expect_request(\" http://example.com/resource\" ) as first:
78727885 await page.click('button')
78737886 first_request = await first.value
78747887
7888+ # or with a lambda
78757889 async with page.expect_request(lambda request: request.url == \" http://example.com\" and request.method == \" get\" ) as second:
78767890 await page.click('img')
78777891 second_request = await second.value
@@ -7906,7 +7920,7 @@ def expect_response(
79067920 ) -> AsyncEventContextManager ["Response" ]:
79077921 """Page.expect_response
79087922
7909- Returns the matched response.
7923+ Returns the matched response. See [waiting for event](./events.md#waiting-for-event) for more details about events.
79107924
79117925 ```py
79127926 async with page.expect_response(\" https://example.com/resource\" ) as response_info:
@@ -8481,6 +8495,18 @@ async def route(
84818495 await browser.close()
84828496 ```
84838497
8498+ It is possible to examine the request to decide the route action. For example, mocking all requests that contain some
8499+ post data, and leaving all other requests as is:
8500+
8501+ ```py
8502+ def handle_route(route):
8503+ if (\" my-string\" in route.request.post_data)
8504+ route.fulfill(body=\" mocked-data\" )
8505+ else
8506+ route.continue_()
8507+ await context.route(\" /api/**\" , handle_route)
8508+ ```
8509+
84848510 Page routes (set up with `page.route()`) take precedence over browser context routes when request matches both
84858511 handlers.
84868512
@@ -9567,7 +9593,12 @@ async def launch_persistent_context(
95679593 )
95689594
95699595 async def connect_over_cdp (
9570- self , endpoint_url : str , * , timeout : float = None , slow_mo : float = None
9596+ self ,
9597+ endpoint_url : str ,
9598+ * ,
9599+ timeout : float = None ,
9600+ slow_mo : float = None ,
9601+ headers : typing .Optional [typing .Dict [str , str ]] = None
95719602 ) -> "Browser" :
95729603 """BrowserType.connect_over_cdp
95739604
@@ -9588,6 +9619,8 @@ async def connect_over_cdp(
95889619 slow_mo : Union[float, NoneType]
95899620 Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going on.
95909621 Defaults to 0.
9622+ headers : Union[Dict[str, str], NoneType]
9623+ Additional HTTP headers to be sent with connect request. Optional.
95919624
95929625 Returns
95939626 -------
@@ -9598,13 +9631,21 @@ async def connect_over_cdp(
95989631 await self ._async (
95999632 "browser_type.connect_over_cdp" ,
96009633 self ._impl_obj .connect_over_cdp (
9601- endpointURL = endpoint_url , timeout = timeout , slow_mo = slow_mo
9634+ endpointURL = endpoint_url ,
9635+ timeout = timeout ,
9636+ slow_mo = slow_mo ,
9637+ headers = mapping .to_impl (headers ),
96029638 ),
96039639 )
96049640 )
96059641
96069642 async def connect (
9607- self , ws_endpoint : str , * , timeout : float = None , slow_mo : float = None
9643+ self ,
9644+ ws_endpoint : str ,
9645+ * ,
9646+ timeout : float = None ,
9647+ slow_mo : float = None ,
9648+ headers : typing .Optional [typing .Dict [str , str ]] = None
96089649 ) -> "Browser" :
96099650 """BrowserType.connect
96109651
@@ -9620,6 +9661,8 @@ async def connect(
96209661 slow_mo : Union[float, NoneType]
96219662 Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going on.
96229663 Defaults to 0.
9664+ headers : Union[Dict[str, str], NoneType]
9665+ Additional HTTP headers to be sent with web socket connect request. Optional.
96239666
96249667 Returns
96259668 -------
@@ -9630,7 +9673,10 @@ async def connect(
96309673 await self ._async (
96319674 "browser_type.connect" ,
96329675 self ._impl_obj .connect (
9633- ws_endpoint = ws_endpoint , timeout = timeout , slow_mo = slow_mo
9676+ ws_endpoint = ws_endpoint ,
9677+ timeout = timeout ,
9678+ slow_mo = slow_mo ,
9679+ headers = mapping .to_impl (headers ),
96349680 ),
96359681 )
96369682 )
0 commit comments