Skip to content

Commit 979182b

Browse files
authored
chore: roll to Playwright ToT (microsoft#481)
1 parent 28bba74 commit 979182b

14 files changed

+544
-777
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ Playwright is a Python library to automate [Chromium](https://www.chromium.org/H
66

77
| | Linux | macOS | Windows |
88
| :--- | :---: | :---: | :---: |
9-
| Chromium <!-- GEN:chromium-version -->90.0.4392.0<!-- GEN:stop --> ||||
9+
| Chromium <!-- GEN:chromium-version -->90.0.4396.0<!-- GEN:stop --> ||||
1010
| WebKit <!-- GEN:webkit-version -->14.1<!-- GEN:stop --> ||||
11-
| Firefox <!-- GEN:firefox-version -->85.0b5<!-- GEN:stop --> ||||
11+
| Firefox <!-- GEN:firefox-version -->85.0b10<!-- GEN:stop --> ||||
1212

1313
Headless execution is supported for all browsers on all platforms.
1414

playwright/_impl/_browser_context.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ async def close(self) -> None:
235235
if not is_safe_close_error(e):
236236
raise e
237237

238+
async def _pause(self) -> None:
239+
await self._channel.send("pause")
240+
238241
async def storage_state(self, path: Union[str, Path] = None) -> StorageState:
239242
result = await self._channel.send_return_as_dict("storageState")
240243
if path:

playwright/_impl/_element_handle.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,15 +243,13 @@ async def eval_on_selector(
243243
selector: str,
244244
expression: str,
245245
arg: Serializable = None,
246-
force_expr: bool = None,
247246
) -> Any:
248247
return parse_result(
249248
await self._channel.send(
250249
"evalOnSelector",
251250
dict(
252251
selector=selector,
253252
expression=expression,
254-
isFunction=not (force_expr),
255253
arg=serialize_argument(arg),
256254
),
257255
)
@@ -262,15 +260,13 @@ async def eval_on_selector_all(
262260
selector: str,
263261
expression: str,
264262
arg: Serializable = None,
265-
force_expr: bool = None,
266263
) -> Any:
267264
return parse_result(
268265
await self._channel.send(
269266
"evalOnSelectorAll",
270267
dict(
271268
selector=selector,
272269
expression=expression,
273-
isFunction=not (force_expr),
274270
arg=serialize_argument(arg),
275271
),
276272
)

playwright/_impl/_frame.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
MouseButton,
3737
URLMatch,
3838
URLMatcher,
39-
is_function_body,
4039
locals_to_params,
4140
monotonic_time,
4241
)
@@ -195,33 +194,25 @@ async def wait_for_load_state(
195194
async def frame_element(self) -> ElementHandle:
196195
return from_channel(await self._channel.send("frameElement"))
197196

198-
async def evaluate(
199-
self, expression: str, arg: Serializable = None, force_expr: bool = None
200-
) -> Any:
201-
if not is_function_body(expression):
202-
force_expr = True
197+
async def evaluate(self, expression: str, arg: Serializable = None) -> Any:
203198
return parse_result(
204199
await self._channel.send(
205200
"evaluateExpression",
206201
dict(
207202
expression=expression,
208-
isFunction=not (force_expr),
209203
arg=serialize_argument(arg),
210204
),
211205
)
212206
)
213207

214208
async def evaluate_handle(
215-
self, expression: str, arg: Serializable = None, force_expr: bool = None
209+
self, expression: str, arg: Serializable = None
216210
) -> JSHandle:
217-
if not is_function_body(expression):
218-
force_expr = True
219211
return from_channel(
220212
await self._channel.send(
221213
"evaluateExpressionHandle",
222214
dict(
223215
expression=expression,
224-
isFunction=not (force_expr),
225216
arg=serialize_argument(arg),
226217
),
227218
)
@@ -281,15 +272,13 @@ async def eval_on_selector(
281272
selector: str,
282273
expression: str,
283274
arg: Serializable = None,
284-
force_expr: bool = None,
285275
) -> Any:
286276
return parse_result(
287277
await self._channel.send(
288278
"evalOnSelector",
289279
dict(
290280
selector=selector,
291281
expression=expression,
292-
isFunction=not (force_expr),
293282
arg=serialize_argument(arg),
294283
),
295284
)
@@ -300,15 +289,13 @@ async def eval_on_selector_all(
300289
selector: str,
301290
expression: str,
302291
arg: Serializable = None,
303-
force_expr: bool = None,
304292
) -> Any:
305293
return parse_result(
306294
await self._channel.send(
307295
"evalOnSelectorAll",
308296
dict(
309297
selector=selector,
310298
expression=expression,
311-
isFunction=not (force_expr),
312299
arg=serialize_argument(arg),
313300
),
314301
)
@@ -516,14 +503,10 @@ async def wait_for_function(
516503
self,
517504
expression: str,
518505
arg: Serializable = None,
519-
force_expr: bool = None,
520506
timeout: float = None,
521507
polling: Union[float, Literal["raf"]] = None,
522508
) -> JSHandle:
523-
if not is_function_body(expression):
524-
force_expr = True
525509
params = locals_to_params(locals())
526-
params["isFunction"] = not (force_expr)
527510
params["arg"] = serialize_argument(arg)
528511
return from_channel(await self._channel.send("waitForFunction", params))
529512

playwright/_impl/_helper.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,6 @@ def patch_error_message(message: Optional[str]) -> Optional[str]:
175175
return message
176176

177177

178-
def is_function_body(expression: str) -> bool:
179-
expression = expression.strip()
180-
return (
181-
expression.startswith("function")
182-
or expression.startswith("async ")
183-
or "=>" in expression
184-
)
185-
186-
187178
def locals_to_params(args: Dict) -> Dict:
188179
copy = {}
189180
for key in args:

playwright/_impl/_js_handle.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
from playwright._impl._api_types import Error
2020
from playwright._impl._connection import ChannelOwner, from_channel
21-
from playwright._impl._helper import is_function_body
2221

2322
if TYPE_CHECKING: # pragma: no cover
2423
from playwright._impl._element_handle import ElementHandle
@@ -43,33 +42,25 @@ def __str__(self) -> str:
4342
def _on_preview_updated(self, preview: str) -> None:
4443
self._preview = preview
4544

46-
async def evaluate(
47-
self, expression: str, arg: Serializable = None, force_expr: bool = None
48-
) -> Any:
49-
if not is_function_body(expression):
50-
force_expr = True
45+
async def evaluate(self, expression: str, arg: Serializable = None) -> Any:
5146
return parse_result(
5247
await self._channel.send(
5348
"evaluateExpression",
5449
dict(
5550
expression=expression,
56-
isFunction=not (force_expr),
5751
arg=serialize_argument(arg),
5852
),
5953
)
6054
)
6155

6256
async def evaluate_handle(
63-
self, expression: str, arg: Serializable = None, force_expr: bool = None
57+
self, expression: str, arg: Serializable = None
6458
) -> "JSHandle":
65-
if not is_function_body(expression):
66-
force_expr = True
6759
return from_channel(
6860
await self._channel.send(
6961
"evaluateExpressionHandle",
7062
dict(
7163
expression=expression,
72-
isFunction=not (force_expr),
7364
arg=serialize_argument(arg),
7465
),
7566
)

playwright/_impl/_page.py

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
URLMatcher,
5353
URLMatchRequest,
5454
URLMatchResponse,
55-
is_function_body,
5655
is_safe_close_error,
5756
locals_to_params,
5857
parse_error,
@@ -139,12 +138,7 @@ def __init__(
139138
),
140139
)
141140
self._channel.on("crash", lambda _: self._on_crash())
142-
self._channel.on(
143-
"dialog",
144-
lambda params: self.emit(
145-
Page.Events.Dialog, from_channel(params["dialog"])
146-
),
147-
)
141+
self._channel.on("dialog", lambda params: self._on_dialog(params))
148142
self._channel.on(
149143
"domcontentloaded", lambda _: self.emit(Page.Events.DOMContentLoaded)
150144
)
@@ -290,6 +284,13 @@ def _on_close(self) -> None:
290284
def _on_crash(self) -> None:
291285
self.emit(Page.Events.Crash)
292286

287+
def _on_dialog(self, params: Any) -> None:
288+
dialog = from_channel(params["dialog"])
289+
if self.listeners(Page.Events.Dialog):
290+
self.emit(Page.Events.Dialog, dialog)
291+
else:
292+
asyncio.create_task(dialog.dismiss())
293+
293294
def _add_event_handler(self, event: str, k: Any, v: Any) -> None:
294295
if event == Page.Events.FileChooser and len(self.listeners(event)) == 0:
295296
self._channel.send_no_reply(
@@ -375,39 +376,29 @@ async def dispatch_event(
375376
) -> None:
376377
return await self._main_frame.dispatch_event(**locals_to_params(locals()))
377378

378-
async def evaluate(
379-
self, expression: str, arg: Serializable = None, force_expr: bool = None
380-
) -> Any:
381-
return await self._main_frame.evaluate(expression, arg, force_expr=force_expr)
379+
async def evaluate(self, expression: str, arg: Serializable = None) -> Any:
380+
return await self._main_frame.evaluate(expression, arg)
382381

383382
async def evaluate_handle(
384-
self, expression: str, arg: Serializable = None, force_expr: bool = None
383+
self, expression: str, arg: Serializable = None
385384
) -> JSHandle:
386-
return await self._main_frame.evaluate_handle(
387-
expression, arg, force_expr=force_expr
388-
)
385+
return await self._main_frame.evaluate_handle(expression, arg)
389386

390387
async def eval_on_selector(
391388
self,
392389
selector: str,
393390
expression: str,
394391
arg: Serializable = None,
395-
force_expr: bool = None,
396392
) -> Any:
397-
return await self._main_frame.eval_on_selector(
398-
selector, expression, arg, force_expr=force_expr
399-
)
393+
return await self._main_frame.eval_on_selector(selector, expression, arg)
400394

401395
async def eval_on_selector_all(
402396
self,
403397
selector: str,
404398
expression: str,
405399
arg: Serializable = None,
406-
force_expr: bool = None,
407400
) -> Any:
408-
return await self._main_frame.eval_on_selector_all(
409-
selector, expression, arg, force_expr=force_expr
410-
)
401+
return await self._main_frame.eval_on_selector_all(selector, expression, arg)
411402

412403
async def add_script_tag(
413404
self,
@@ -729,18 +720,18 @@ async def wait_for_function(
729720
self,
730721
expression: str,
731722
arg: Serializable = None,
732-
force_expr: bool = None,
733723
timeout: float = None,
734724
polling: Union[float, Literal["raf"]] = None,
735725
) -> JSHandle:
736-
if not is_function_body(expression):
737-
force_expr = True
738726
return await self._main_frame.wait_for_function(**locals_to_params(locals()))
739727

740728
@property
741729
def workers(self) -> List["Worker"]:
742730
return self._workers.copy()
743731

732+
async def pause(self) -> None:
733+
await self._browser_context._pause()
734+
744735
async def pdf(
745736
self,
746737
scale: float = None,
@@ -903,31 +894,25 @@ def _on_close(self) -> None:
903894
def url(self) -> str:
904895
return self._initializer["url"]
905896

906-
async def evaluate(
907-
self, expression: str, arg: Serializable = None, force_expr: bool = None
908-
) -> Any:
909-
if not is_function_body(expression):
910-
force_expr = True
897+
async def evaluate(self, expression: str, arg: Serializable = None) -> Any:
911898
return parse_result(
912899
await self._channel.send(
913900
"evaluateExpression",
914901
dict(
915902
expression=expression,
916-
isFunction=not (force_expr),
917903
arg=serialize_argument(arg),
918904
),
919905
)
920906
)
921907

922908
async def evaluate_handle(
923-
self, expression: str, arg: Serializable = None, force_expr: bool = None
909+
self, expression: str, arg: Serializable = None
924910
) -> JSHandle:
925911
return from_channel(
926912
await self._channel.send(
927913
"evaluateExpressionHandle",
928914
dict(
929915
expression=expression,
930-
isFunction=not (force_expr),
931916
arg=serialize_argument(arg),
932917
),
933918
)

0 commit comments

Comments
 (0)