Skip to content

Commit 3713a32

Browse files
authored
chore: explicit timeout config for send (#2900)
1 parent fdca00c commit 3713a32

26 files changed

+478
-236
lines changed

playwright/_impl/_accessibility.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,5 @@ async def snapshot(
6565
params = locals_to_params(locals())
6666
if root:
6767
params["root"] = root._channel
68-
result = await self._channel.send("accessibilitySnapshot", params)
68+
result = await self._channel.send("accessibilitySnapshot", None, params)
6969
return _ax_node_from_protocol(result) if result else None

playwright/_impl/_artifact.py

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,55 @@ async def path_after_finished(self) -> pathlib.Path:
3333
raise Error(
3434
"Path is not available when using browser_type.connect(). Use save_as() to save a local copy."
3535
)
36-
path = await self._channel.send("pathAfterFinished")
36+
path = await self._channel.send(
37+
"pathAfterFinished",
38+
None,
39+
)
3740
return pathlib.Path(path)
3841

3942
async def save_as(self, path: Union[str, Path]) -> None:
40-
stream = cast(Stream, from_channel(await self._channel.send("saveAsStream")))
43+
stream = cast(
44+
Stream,
45+
from_channel(
46+
await self._channel.send(
47+
"saveAsStream",
48+
None,
49+
)
50+
),
51+
)
4152
make_dirs_for_file(path)
4253
await stream.save_as(path)
4354

4455
async def failure(self) -> Optional[str]:
45-
reason = await self._channel.send("failure")
56+
reason = await self._channel.send(
57+
"failure",
58+
None,
59+
)
4660
if reason is None:
4761
return None
4862
return patch_error_message(reason)
4963

5064
async def delete(self) -> None:
51-
await self._channel.send("delete")
65+
await self._channel.send(
66+
"delete",
67+
None,
68+
)
5269

5370
async def read_info_buffer(self) -> bytes:
54-
stream = cast(Stream, from_channel(await self._channel.send("stream")))
71+
stream = cast(
72+
Stream,
73+
from_channel(
74+
await self._channel.send(
75+
"stream",
76+
None,
77+
)
78+
),
79+
)
5580
buffer = await stream.read_all()
5681
return buffer
5782

5883
async def cancel(self) -> None: # pyright: ignore[reportIncompatibleMethodOverride]
59-
await self._channel.send("cancel")
84+
await self._channel.send(
85+
"cancel",
86+
None,
87+
)

playwright/_impl/_browser.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ async def new_context(
168168
assert self._browser_type is not None
169169
await self._browser_type._prepare_browser_context_params(params)
170170

171-
channel = await self._channel.send("newContext", params)
171+
channel = await self._channel.send("newContext", None, params)
172172
context = cast(BrowserContext, from_channel(channel))
173173
await context._initialize_har_from_options(
174174
record_har_content=recordHarContent,
@@ -235,7 +235,7 @@ async def close(self, reason: str = None) -> None:
235235
if self._should_close_connection_on_close:
236236
await self._connection.stop_async()
237237
else:
238-
await self._channel.send("close", {"reason": reason})
238+
await self._channel.send("close", None, {"reason": reason})
239239
except Exception as e:
240240
if not is_target_closed_error(e):
241241
raise e
@@ -245,7 +245,7 @@ def version(self) -> str:
245245
return self._initializer["version"]
246246

247247
async def new_browser_cdp_session(self) -> CDPSession:
248-
return from_channel(await self._channel.send("newBrowserCDPSession"))
248+
return from_channel(await self._channel.send("newBrowserCDPSession", None))
249249

250250
async def start_tracing(
251251
self,
@@ -260,10 +260,12 @@ async def start_tracing(
260260
if path:
261261
self._cr_tracing_path = str(path)
262262
params["path"] = str(path)
263-
await self._channel.send("startTracing", params)
263+
await self._channel.send("startTracing", None, params)
264264

265265
async def stop_tracing(self) -> bytes:
266-
artifact = cast(Artifact, from_channel(await self._channel.send("stopTracing")))
266+
artifact = cast(
267+
Artifact, from_channel(await self._channel.send("stopTracing", None))
268+
)
267269
buffer = await artifact.read_info_buffer()
268270
await artifact.delete()
269271
if self._cr_tracing_path:

playwright/_impl/_browser_context.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -330,17 +330,17 @@ async def _initialize_har_from_options(
330330
async def new_page(self) -> Page:
331331
if self._owner_page:
332332
raise Error("Please use browser.new_context()")
333-
return from_channel(await self._channel.send("newPage"))
333+
return from_channel(await self._channel.send("newPage", None))
334334

335335
async def cookies(self, urls: Union[str, Sequence[str]] = None) -> List[Cookie]:
336336
if urls is None:
337337
urls = []
338338
if isinstance(urls, str):
339339
urls = [urls]
340-
return await self._channel.send("cookies", dict(urls=urls))
340+
return await self._channel.send("cookies", None, dict(urls=urls))
341341

342342
async def add_cookies(self, cookies: Sequence[SetCookieParam]) -> None:
343-
await self._channel.send("addCookies", dict(cookies=cookies))
343+
await self._channel.send("addCookies", None, dict(cookies=cookies))
344344

345345
async def clear_cookies(
346346
self,
@@ -350,6 +350,7 @@ async def clear_cookies(
350350
) -> None:
351351
await self._channel.send(
352352
"clearCookies",
353+
None,
353354
{
354355
"name": name if isinstance(name, str) else None,
355356
"nameRegexSource": name.pattern if isinstance(name, Pattern) else None,
@@ -374,21 +375,21 @@ async def clear_cookies(
374375
async def grant_permissions(
375376
self, permissions: Sequence[str], origin: str = None
376377
) -> None:
377-
await self._channel.send("grantPermissions", locals_to_params(locals()))
378+
await self._channel.send("grantPermissions", None, locals_to_params(locals()))
378379

379380
async def clear_permissions(self) -> None:
380-
await self._channel.send("clearPermissions")
381+
await self._channel.send("clearPermissions", None)
381382

382383
async def set_geolocation(self, geolocation: Geolocation = None) -> None:
383-
await self._channel.send("setGeolocation", locals_to_params(locals()))
384+
await self._channel.send("setGeolocation", None, locals_to_params(locals()))
384385

385386
async def set_extra_http_headers(self, headers: Dict[str, str]) -> None:
386387
await self._channel.send(
387-
"setExtraHTTPHeaders", dict(headers=serialize_headers(headers))
388+
"setExtraHTTPHeaders", None, dict(headers=serialize_headers(headers))
388389
)
389390

390391
async def set_offline(self, offline: bool) -> None:
391-
await self._channel.send("setOffline", dict(offline=offline))
392+
await self._channel.send("setOffline", None, dict(offline=offline))
392393

393394
async def add_init_script(
394395
self, script: str = None, path: Union[str, Path] = None
@@ -397,7 +398,7 @@ async def add_init_script(
397398
script = (await async_readfile(path)).decode()
398399
if not isinstance(script, str):
399400
raise Error("Either path or script parameter must be specified")
400-
await self._channel.send("addInitScript", dict(source=script))
401+
await self._channel.send("addInitScript", None, dict(source=script))
401402

402403
async def expose_binding(
403404
self, name: str, callback: Callable, handle: bool = None
@@ -411,7 +412,7 @@ async def expose_binding(
411412
raise Error(f'Function "{name}" has been already registered')
412413
self._bindings[name] = callback
413414
await self._channel.send(
414-
"exposeBinding", dict(name=name, needsHandle=handle or False)
415+
"exposeBinding", None, dict(name=name, needsHandle=handle or False)
415416
)
416417

417418
async def expose_function(self, name: str, callback: Callable) -> None:
@@ -499,7 +500,7 @@ async def _record_into_har(
499500
}
500501
if page:
501502
params["page"] = page._channel
502-
har_id = await self._channel.send("harStart", params)
503+
har_id = await self._channel.send("harStart", None, params)
503504
self._har_recorders[har_id] = {
504505
"path": str(har),
505506
"content": update_content,
@@ -535,15 +536,15 @@ async def route_from_har(
535536
async def _update_interception_patterns(self) -> None:
536537
patterns = RouteHandler.prepare_interception_patterns(self._routes)
537538
await self._channel.send(
538-
"setNetworkInterceptionPatterns", {"patterns": patterns}
539+
"setNetworkInterceptionPatterns", None, {"patterns": patterns}
539540
)
540541

541542
async def _update_web_socket_interception_patterns(self) -> None:
542543
patterns = WebSocketRouteHandler.prepare_interception_patterns(
543544
self._web_socket_routes
544545
)
545546
await self._channel.send(
546-
"setWebSocketInterceptionPatterns", {"patterns": patterns}
547+
"setWebSocketInterceptionPatterns", None, {"patterns": patterns}
547548
)
548549

549550
def expect_event(
@@ -596,7 +597,7 @@ async def _inner_close() -> None:
596597
har = cast(
597598
Artifact,
598599
from_channel(
599-
await self._channel.send("harExport", {"harId": har_id})
600+
await self._channel.send("harExport", None, {"harId": har_id})
600601
),
601602
)
602603
# Server side will compress artifact if content is attach or if file is .zip.
@@ -615,14 +616,14 @@ async def _inner_close() -> None:
615616
await har.delete()
616617

617618
await self._channel._connection.wrap_api_call(_inner_close, True)
618-
await self._channel.send("close", {"reason": reason})
619+
await self._channel.send("close", None, {"reason": reason})
619620
await self._closed_future
620621

621622
async def storage_state(
622623
self, path: Union[str, Path] = None, indexedDB: bool = None
623624
) -> StorageState:
624625
result = await self._channel.send_return_as_dict(
625-
"storageState", {"indexedDB": indexedDB}
626+
"storageState", None, {"indexedDB": indexedDB}
626627
)
627628
if path:
628629
await async_writefile(path, json.dumps(result))
@@ -749,7 +750,7 @@ async def new_cdp_session(self, page: Union[Page, Frame]) -> CDPSession:
749750
params["frame"] = page._channel
750751
else:
751752
raise Error("page: expected Page or Frame")
752-
return from_channel(await self._channel.send("newCDPSession", params))
753+
return from_channel(await self._channel.send("newCDPSession", None, params))
753754

754755
@property
755756
def tracing(self) -> Tracing:

playwright/_impl/_browser_type.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,12 @@ async def launch(
9393
params = locals_to_params(locals())
9494
normalize_launch_params(params)
9595
browser = cast(
96-
Browser, from_channel(await self._channel.send("launch", params))
96+
Browser,
97+
from_channel(
98+
await self._channel.send(
99+
"launch", TimeoutSettings.launch_timeout, params
100+
)
101+
),
97102
)
98103
browser._connect_to_browser_type(
99104
self, str(tracesDir) if tracesDir is not None else None
@@ -159,7 +164,7 @@ async def launch_persistent_context(
159164
await self._prepare_browser_context_params(params)
160165
normalize_launch_params(params)
161166
result = await self._channel.send_return_as_dict(
162-
"launchPersistentContext", params
167+
"launchPersistentContext", TimeoutSettings.launch_timeout, params
163168
)
164169
browser = cast(
165170
Browser,
@@ -197,10 +202,11 @@ async def connect_over_cdp(
197202
headers: Dict[str, str] = None,
198203
) -> Browser:
199204
params = locals_to_params(locals())
200-
params["timeout"] = TimeoutSettings.launch_timeout(timeout)
201205
if params.get("headers"):
202206
params["headers"] = serialize_headers(params["headers"])
203-
response = await self._channel.send_return_as_dict("connectOverCDP", params)
207+
response = await self._channel.send_return_as_dict(
208+
"connectOverCDP", TimeoutSettings.launch_timeout, params
209+
)
204210
browser = cast(Browser, from_channel(response["browser"]))
205211
browser._connect_to_browser_type(self, None)
206212

@@ -222,6 +228,7 @@ async def connect(
222228
pipe_channel = (
223229
await local_utils._channel.send_return_as_dict(
224230
"connect",
231+
None,
225232
{
226233
"wsEndpoint": wsEndpoint,
227234
"headers": headers,
@@ -355,4 +362,3 @@ def normalize_launch_params(params: Dict) -> None:
355362
params["downloadsPath"] = str(Path(params["downloadsPath"]))
356363
if "tracesDir" in params:
357364
params["tracesDir"] = str(Path(params["tracesDir"]))
358-
params["timeout"] = TimeoutSettings.launch_timeout(params.get("timeout"))

playwright/_impl/_cdp_session.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ def _on_event(self, params: Any) -> None:
2929
self.emit(params["method"], params.get("params"))
3030

3131
async def send(self, method: str, params: Dict = None) -> Dict:
32-
return await self._channel.send("send", locals_to_params(locals()))
32+
return await self._channel.send("send", None, locals_to_params(locals()))
3333

3434
async def detach(self) -> None:
35-
await self._channel.send("detach")
35+
await self._channel.send(
36+
"detach",
37+
None,
38+
)

playwright/_impl/_clock.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,46 +27,64 @@ def __init__(self, browser_context: "BrowserContext") -> None:
2727

2828
async def install(self, time: Union[float, str, datetime.datetime] = None) -> None:
2929
await self._browser_context._channel.send(
30-
"clockInstall", parse_time(time) if time is not None else {}
30+
"clockInstall",
31+
None,
32+
parse_time(time) if time is not None else {},
3133
)
3234

3335
async def fast_forward(
3436
self,
3537
ticks: Union[int, str],
3638
) -> None:
3739
await self._browser_context._channel.send(
38-
"clockFastForward", parse_ticks(ticks)
40+
"clockFastForward",
41+
None,
42+
parse_ticks(ticks),
3943
)
4044

4145
async def pause_at(
4246
self,
4347
time: Union[float, str, datetime.datetime],
4448
) -> None:
45-
await self._browser_context._channel.send("clockPauseAt", parse_time(time))
49+
await self._browser_context._channel.send(
50+
"clockPauseAt",
51+
None,
52+
parse_time(time),
53+
)
4654

4755
async def resume(
4856
self,
4957
) -> None:
50-
await self._browser_context._channel.send("clockResume")
58+
await self._browser_context._channel.send("clockResume", None)
5159

5260
async def run_for(
5361
self,
5462
ticks: Union[int, str],
5563
) -> None:
56-
await self._browser_context._channel.send("clockRunFor", parse_ticks(ticks))
64+
await self._browser_context._channel.send(
65+
"clockRunFor",
66+
None,
67+
parse_ticks(ticks),
68+
)
5769

5870
async def set_fixed_time(
5971
self,
6072
time: Union[float, str, datetime.datetime],
6173
) -> None:
62-
await self._browser_context._channel.send("clockSetFixedTime", parse_time(time))
74+
await self._browser_context._channel.send(
75+
"clockSetFixedTime",
76+
None,
77+
parse_time(time),
78+
)
6379

6480
async def set_system_time(
6581
self,
6682
time: Union[float, str, datetime.datetime],
6783
) -> None:
6884
await self._browser_context._channel.send(
69-
"clockSetSystemTime", parse_time(time)
85+
"clockSetSystemTime",
86+
None,
87+
parse_time(time),
7088
)
7189

7290

0 commit comments

Comments
 (0)