Skip to content

Commit 535debf

Browse files
committed
Only set timeouts on necessary protocol calls
1 parent 68a832b commit 535debf

File tree

9 files changed

+68
-96
lines changed

9 files changed

+68
-96
lines changed

playwright/_impl/_browser_type.py

Lines changed: 8 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", None, 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", None, params
167+
"launchPersistentContext", TimeoutSettings.launch_timeout, params
163168
)
164169
browser = cast(
165170
Browser,
@@ -197,11 +202,10 @@ 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"])
203207
response = await self._channel.send_return_as_dict(
204-
"connectOverCDP", None, params
208+
"connectOverCDP", TimeoutSettings.launch_timeout, params
205209
)
206210
browser = cast(Browser, from_channel(response["browser"]))
207211
browser._connect_to_browser_type(self, None)
@@ -358,4 +362,3 @@ def normalize_launch_params(params: Dict) -> None:
358362
params["downloadsPath"] = str(Path(params["downloadsPath"]))
359363
if "tracesDir" in params:
360364
params["tracesDir"] = str(Path(params["tracesDir"]))
361-
params["timeout"] = TimeoutSettings.launch_timeout(params.get("timeout"))

playwright/_impl/_clock.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def __init__(self, browser_context: "BrowserContext") -> None:
2828
async def install(self, time: Union[float, str, datetime.datetime] = None) -> None:
2929
await self._browser_context._channel.send(
3030
"clockInstall",
31-
self._browser_context._timeout_settings.timeout,
31+
None,
3232
parse_time(time) if time is not None else {},
3333
)
3434

@@ -38,7 +38,7 @@ async def fast_forward(
3838
) -> None:
3939
await self._browser_context._channel.send(
4040
"clockFastForward",
41-
self._browser_context._timeout_settings.timeout,
41+
None,
4242
parse_ticks(ticks),
4343
)
4444

@@ -48,24 +48,22 @@ async def pause_at(
4848
) -> None:
4949
await self._browser_context._channel.send(
5050
"clockPauseAt",
51-
self._browser_context._timeout_settings.timeout,
51+
None,
5252
parse_time(time),
5353
)
5454

5555
async def resume(
5656
self,
5757
) -> None:
58-
await self._browser_context._channel.send(
59-
"clockResume", self._browser_context._timeout_settings.timeout
60-
)
58+
await self._browser_context._channel.send("clockResume", None)
6159

6260
async def run_for(
6361
self,
6462
ticks: Union[int, str],
6563
) -> None:
6664
await self._browser_context._channel.send(
6765
"clockRunFor",
68-
self._browser_context._timeout_settings.timeout,
66+
None,
6967
parse_ticks(ticks),
7068
)
7169

@@ -75,7 +73,7 @@ async def set_fixed_time(
7573
) -> None:
7674
await self._browser_context._channel.send(
7775
"clockSetFixedTime",
78-
self._browser_context._timeout_settings.timeout,
76+
None,
7977
parse_time(time),
8078
)
8179

@@ -85,7 +83,7 @@ async def set_system_time(
8583
) -> None:
8684
await self._browser_context._channel.send(
8785
"clockSetSystemTime",
88-
self._browser_context._timeout_settings.timeout,
86+
None,
8987
parse_time(time),
9088
)
9189

playwright/_impl/_connection.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ def __init__(self, connection: "Connection", object: "ChannelOwner") -> None:
5757
self._guid = object._guid
5858
self._object = object
5959
self.on("error", lambda exc: self._connection._on_event_listener_error(exc))
60-
self._timeout_calculator: TimeoutCalculator = None
6160

6261
async def send(
6362
self,

playwright/_impl/_element_handle.py

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -66,51 +66,45 @@ def as_element(self) -> Optional["ElementHandle"]:
6666
return self
6767

6868
async def owner_frame(self) -> Optional["Frame"]:
69-
return from_nullable_channel(
70-
await self._channel.send("ownerFrame", self._frame._timeout)
71-
)
69+
return from_nullable_channel(await self._channel.send("ownerFrame", None))
7270

7371
async def content_frame(self) -> Optional["Frame"]:
74-
return from_nullable_channel(
75-
await self._channel.send("contentFrame", self._frame._timeout)
76-
)
72+
return from_nullable_channel(await self._channel.send("contentFrame", None))
7773

7874
async def get_attribute(self, name: str) -> Optional[str]:
79-
return await self._channel.send(
80-
"getAttribute", self._frame._timeout, dict(name=name)
81-
)
75+
return await self._channel.send("getAttribute", None, dict(name=name))
8276

8377
async def text_content(self) -> Optional[str]:
84-
return await self._channel.send("textContent", self._frame._timeout)
78+
return await self._channel.send("textContent", None)
8579

8680
async def inner_text(self) -> str:
87-
return await self._channel.send("innerText", self._frame._timeout)
81+
return await self._channel.send("innerText", None)
8882

8983
async def inner_html(self) -> str:
90-
return await self._channel.send("innerHTML", self._frame._timeout)
84+
return await self._channel.send("innerHTML", None)
9185

9286
async def is_checked(self) -> bool:
93-
return await self._channel.send("isChecked", self._frame._timeout)
87+
return await self._channel.send("isChecked", None)
9488

9589
async def is_disabled(self) -> bool:
96-
return await self._channel.send("isDisabled", self._frame._timeout)
90+
return await self._channel.send("isDisabled", None)
9791

9892
async def is_editable(self) -> bool:
99-
return await self._channel.send("isEditable", self._frame._timeout)
93+
return await self._channel.send("isEditable", None)
10094

10195
async def is_enabled(self) -> bool:
102-
return await self._channel.send("isEnabled", self._frame._timeout)
96+
return await self._channel.send("isEnabled", None)
10397

10498
async def is_hidden(self) -> bool:
105-
return await self._channel.send("isHidden", self._frame._timeout)
99+
return await self._channel.send("isHidden", None)
106100

107101
async def is_visible(self) -> bool:
108-
return await self._channel.send("isVisible", self._frame._timeout)
102+
return await self._channel.send("isVisible", None)
109103

110104
async def dispatch_event(self, type: str, eventInit: Dict = None) -> None:
111105
await self._channel.send(
112106
"dispatchEvent",
113-
self._frame._timeout,
107+
None,
114108
dict(type=type, eventInit=serialize_argument(eventInit)),
115109
)
116110

@@ -238,7 +232,7 @@ async def set_input_files(
238232
)
239233

240234
async def focus(self) -> None:
241-
await self._channel.send("focus", self._frame._timeout)
235+
await self._channel.send("focus", None)
242236

243237
async def type(
244238
self,
@@ -311,7 +305,7 @@ async def uncheck(
311305
)
312306

313307
async def bounding_box(self) -> Optional[FloatRect]:
314-
return await self._channel.send("boundingBox", self._frame._timeout)
308+
return await self._channel.send("boundingBox", None)
315309

316310
async def screenshot(
317311
self,
@@ -353,17 +347,15 @@ async def screenshot(
353347

354348
async def query_selector(self, selector: str) -> Optional["ElementHandle"]:
355349
return from_nullable_channel(
356-
await self._channel.send(
357-
"querySelector", self._frame._timeout, dict(selector=selector)
358-
)
350+
await self._channel.send("querySelector", None, dict(selector=selector))
359351
)
360352

361353
async def query_selector_all(self, selector: str) -> List["ElementHandle"]:
362354
return list(
363355
map(
364356
cast(Callable[[Any], Any], from_nullable_channel),
365357
await self._channel.send(
366-
"querySelectorAll", self._frame._timeout, dict(selector=selector)
358+
"querySelectorAll", None, dict(selector=selector)
367359
),
368360
)
369361
)
@@ -377,7 +369,7 @@ async def eval_on_selector(
377369
return parse_result(
378370
await self._channel.send(
379371
"evalOnSelector",
380-
self._frame._timeout,
372+
None,
381373
dict(
382374
selector=selector,
383375
expression=expression,
@@ -395,7 +387,7 @@ async def eval_on_selector_all(
395387
return parse_result(
396388
await self._channel.send(
397389
"evalOnSelectorAll",
398-
self._frame._timeout,
390+
None,
399391
dict(
400392
selector=selector,
401393
expression=expression,

playwright/_impl/_fetch.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,7 @@ def __init__(
111111
async def dispose(self, reason: str = None) -> None:
112112
self._close_reason = reason
113113
try:
114-
await self._channel.send(
115-
"dispose", self._timeout_settings.timeout, {"reason": reason}
116-
)
114+
await self._channel.send("dispose", None, {"reason": reason})
117115
except Error as e:
118116
if is_target_closed_error(e):
119117
return
@@ -436,7 +434,7 @@ async def storage_state(
436434
indexedDB: bool = None,
437435
) -> StorageState:
438436
result = await self._channel.send_return_as_dict(
439-
"storageState", self._timeout_settings.timeout, {"indexedDB": indexedDB}
437+
"storageState", None, {"indexedDB": indexedDB}
440438
)
441439
if path:
442440
await async_writefile(path, json.dumps(result))

playwright/_impl/_frame.py

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,7 @@ def _on_frame_navigated(self, event: FrameNavigatedEvent) -> None:
126126
self._page.emit("framenavigated", self)
127127

128128
async def _query_count(self, selector: str) -> int:
129-
return await self._channel.send(
130-
"queryCount", self._timeout, {"selector": selector}
131-
)
129+
return await self._channel.send("queryCount", None, {"selector": selector})
132130

133131
@property
134132
def page(self) -> "Page":
@@ -287,13 +285,13 @@ def _navigation_timeout(self, timeout: Optional[float]) -> float:
287285
return timeout_settings.navigation_timeout(timeout)
288286

289287
async def frame_element(self) -> ElementHandle:
290-
return from_channel(await self._channel.send("frameElement", self._timeout))
288+
return from_channel(await self._channel.send("frameElement", None))
291289

292290
async def evaluate(self, expression: str, arg: Serializable = None) -> Any:
293291
return parse_result(
294292
await self._channel.send(
295293
"evaluateExpression",
296-
self._timeout,
294+
None,
297295
dict(
298296
expression=expression,
299297
arg=serialize_argument(arg),
@@ -307,7 +305,7 @@ async def evaluate_handle(
307305
return from_channel(
308306
await self._channel.send(
309307
"evaluateExpressionHandle",
310-
self._timeout,
308+
None,
311309
dict(
312310
expression=expression,
313311
arg=serialize_argument(arg),
@@ -319,17 +317,15 @@ async def query_selector(
319317
self, selector: str, strict: bool = None
320318
) -> Optional[ElementHandle]:
321319
return from_nullable_channel(
322-
await self._channel.send(
323-
"querySelector", self._timeout, locals_to_params(locals())
324-
)
320+
await self._channel.send("querySelector", None, locals_to_params(locals()))
325321
)
326322

327323
async def query_selector_all(self, selector: str) -> List[ElementHandle]:
328324
return list(
329325
map(
330326
from_channel,
331327
await self._channel.send(
332-
"querySelectorAll", self._timeout, dict(selector=selector)
328+
"querySelectorAll", None, dict(selector=selector)
333329
),
334330
)
335331
)
@@ -417,7 +413,7 @@ async def eval_on_selector(
417413
return parse_result(
418414
await self._channel.send(
419415
"evalOnSelector",
420-
self._timeout,
416+
None,
421417
locals_to_params(
422418
dict(
423419
selector=selector,
@@ -438,7 +434,7 @@ async def eval_on_selector_all(
438434
return parse_result(
439435
await self._channel.send(
440436
"evalOnSelectorAll",
441-
self._timeout,
437+
None,
442438
dict(
443439
selector=selector,
444440
expression=expression,
@@ -448,7 +444,7 @@ async def eval_on_selector_all(
448444
)
449445

450446
async def content(self) -> str:
451-
return await self._channel.send("content", self._timeout)
447+
return await self._channel.send("content", None)
452448

453449
async def set_content(
454450
self,
@@ -492,9 +488,7 @@ async def add_script_tag(
492488
(await async_readfile(path)).decode(), path
493489
)
494490
del params["path"]
495-
return from_channel(
496-
await self._channel.send("addScriptTag", self._timeout, params)
497-
)
491+
return from_channel(await self._channel.send("addScriptTag", None, params))
498492

499493
async def add_style_tag(
500494
self, url: str = None, path: Union[str, Path] = None, content: str = None
@@ -508,9 +502,7 @@ async def add_style_tag(
508502
+ "*/"
509503
)
510504
del params["path"]
511-
return from_channel(
512-
await self._channel.send("addStyleTag", self._timeout, params)
513-
)
505+
return from_channel(await self._channel.send("addStyleTag", None, params))
514506

515507
async def click(
516508
self,
@@ -831,7 +823,7 @@ async def wait_for_function(
831823
)
832824

833825
async def title(self) -> str:
834-
return await self._channel.send("title", self._timeout)
826+
return await self._channel.send("title", None)
835827

836828
async def set_checked(
837829
self,
@@ -864,4 +856,4 @@ async def set_checked(
864856
)
865857

866858
async def _highlight(self, selector: str) -> None:
867-
await self._channel.send("highlight", self._timeout, {"selector": selector})
859+
await self._channel.send("highlight", None, {"selector": selector})

0 commit comments

Comments
 (0)