2121
2222import playwright ._impl ._network as network
2323from playwright ._impl ._api_structures import (
24+ ClientCertificate ,
2425 FilePayload ,
2526 FormField ,
2627 Headers ,
4243 object_to_array ,
4344 to_impl ,
4445)
45- from playwright ._impl ._network import serialize_headers
46+ from playwright ._impl ._network import serialize_headers , to_client_certificates_protocol
4647from playwright ._impl ._tracing import Tracing
4748
4849if typing .TYPE_CHECKING :
@@ -71,6 +72,7 @@ async def new_context(
7172 userAgent : str = None ,
7273 timeout : float = None ,
7374 storageState : Union [StorageState , str , Path ] = None ,
75+ clientCertificates : List [ClientCertificate ] = None ,
7476 ) -> "APIRequestContext" :
7577 params = locals_to_params (locals ())
7678 if "storageState" in params :
@@ -81,6 +83,9 @@ async def new_context(
8183 )
8284 if "extraHTTPHeaders" in params :
8385 params ["extraHTTPHeaders" ] = serialize_headers (params ["extraHTTPHeaders" ])
86+ params ["clientCertificates" ] = await to_client_certificates_protocol (
87+ params .get ("clientCertificates" )
88+ )
8489 context = cast (
8590 APIRequestContext ,
8691 from_channel (await self .playwright ._channel .send ("newRequest" , params )),
@@ -118,6 +123,7 @@ async def delete(
118123 failOnStatusCode : bool = None ,
119124 ignoreHTTPSErrors : bool = None ,
120125 maxRedirects : int = None ,
126+ maxRetries : int = None ,
121127 ) -> "APIResponse" :
122128 return await self .fetch (
123129 url ,
@@ -131,6 +137,7 @@ async def delete(
131137 failOnStatusCode = failOnStatusCode ,
132138 ignoreHTTPSErrors = ignoreHTTPSErrors ,
133139 maxRedirects = maxRedirects ,
140+ maxRetries = maxRetries ,
134141 )
135142
136143 async def head (
@@ -145,6 +152,7 @@ async def head(
145152 failOnStatusCode : bool = None ,
146153 ignoreHTTPSErrors : bool = None ,
147154 maxRedirects : int = None ,
155+ maxRetries : int = None ,
148156 ) -> "APIResponse" :
149157 return await self .fetch (
150158 url ,
@@ -158,6 +166,7 @@ async def head(
158166 failOnStatusCode = failOnStatusCode ,
159167 ignoreHTTPSErrors = ignoreHTTPSErrors ,
160168 maxRedirects = maxRedirects ,
169+ maxRetries = maxRetries ,
161170 )
162171
163172 async def get (
@@ -172,6 +181,7 @@ async def get(
172181 failOnStatusCode : bool = None ,
173182 ignoreHTTPSErrors : bool = None ,
174183 maxRedirects : int = None ,
184+ maxRetries : int = None ,
175185 ) -> "APIResponse" :
176186 return await self .fetch (
177187 url ,
@@ -185,6 +195,7 @@ async def get(
185195 failOnStatusCode = failOnStatusCode ,
186196 ignoreHTTPSErrors = ignoreHTTPSErrors ,
187197 maxRedirects = maxRedirects ,
198+ maxRetries = maxRetries ,
188199 )
189200
190201 async def patch (
@@ -199,6 +210,7 @@ async def patch(
199210 failOnStatusCode : bool = None ,
200211 ignoreHTTPSErrors : bool = None ,
201212 maxRedirects : int = None ,
213+ maxRetries : int = None ,
202214 ) -> "APIResponse" :
203215 return await self .fetch (
204216 url ,
@@ -212,6 +224,7 @@ async def patch(
212224 failOnStatusCode = failOnStatusCode ,
213225 ignoreHTTPSErrors = ignoreHTTPSErrors ,
214226 maxRedirects = maxRedirects ,
227+ maxRetries = maxRetries ,
215228 )
216229
217230 async def put (
@@ -226,6 +239,7 @@ async def put(
226239 failOnStatusCode : bool = None ,
227240 ignoreHTTPSErrors : bool = None ,
228241 maxRedirects : int = None ,
242+ maxRetries : int = None ,
229243 ) -> "APIResponse" :
230244 return await self .fetch (
231245 url ,
@@ -239,6 +253,7 @@ async def put(
239253 failOnStatusCode = failOnStatusCode ,
240254 ignoreHTTPSErrors = ignoreHTTPSErrors ,
241255 maxRedirects = maxRedirects ,
256+ maxRetries = maxRetries ,
242257 )
243258
244259 async def post (
@@ -253,6 +268,7 @@ async def post(
253268 failOnStatusCode : bool = None ,
254269 ignoreHTTPSErrors : bool = None ,
255270 maxRedirects : int = None ,
271+ maxRetries : int = None ,
256272 ) -> "APIResponse" :
257273 return await self .fetch (
258274 url ,
@@ -266,6 +282,7 @@ async def post(
266282 failOnStatusCode = failOnStatusCode ,
267283 ignoreHTTPSErrors = ignoreHTTPSErrors ,
268284 maxRedirects = maxRedirects ,
285+ maxRetries = maxRetries ,
269286 )
270287
271288 async def fetch (
@@ -281,6 +298,7 @@ async def fetch(
281298 failOnStatusCode : bool = None ,
282299 ignoreHTTPSErrors : bool = None ,
283300 maxRedirects : int = None ,
301+ maxRetries : int = None ,
284302 ) -> "APIResponse" :
285303 url = urlOrRequest if isinstance (urlOrRequest , str ) else None
286304 request = (
@@ -304,6 +322,7 @@ async def fetch(
304322 failOnStatusCode ,
305323 ignoreHTTPSErrors ,
306324 maxRedirects ,
325+ maxRetries ,
307326 )
308327
309328 async def _inner_fetch (
@@ -320,6 +339,7 @@ async def _inner_fetch(
320339 failOnStatusCode : bool = None ,
321340 ignoreHTTPSErrors : bool = None ,
322341 maxRedirects : int = None ,
342+ maxRetries : int = None ,
323343 ) -> "APIResponse" :
324344 if self ._close_reason :
325345 raise TargetClosedError (self ._close_reason )
@@ -329,6 +349,9 @@ async def _inner_fetch(
329349 assert (
330350 maxRedirects is None or maxRedirects >= 0
331351 ), "'max_redirects' must be greater than or equal to '0'"
352+ assert (
353+ maxRetries is None or maxRetries >= 0
354+ ), "'max_retries' must be greater than or equal to '0'"
332355 url = url or (request .url if request else url )
333356 method = method or (request .method if request else "GET" )
334357 # Cannot call allHeaders() here as the request may be paused inside route handler.
@@ -392,6 +415,7 @@ async def _inner_fetch(
392415 "failOnStatusCode" : failOnStatusCode ,
393416 "ignoreHTTPSErrors" : ignoreHTTPSErrors ,
394417 "maxRedirects" : maxRedirects ,
418+ "maxRetries" : maxRetries ,
395419 },
396420 )
397421 return APIResponse (self , response )
0 commit comments