Skip to content

Commit beb0f22

Browse files
authored
feat(roll): roll Playwright to 1.2.0-next.1596080705875 (microsoft#107)
1 parent 0bb0e34 commit beb0f22

25 files changed

+192
-193
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 🎭 Playwright for Python
22

3-
[![PyPI version](https://badge.fury.io/py/playwright.svg)](https://pypi.python.org/pypi/playwright/) [![Join Slack](https://img.shields.io/badge/join-slack-infomational)](https://join.slack.com/t/playwright/shared_invite/enQtOTEyMTUxMzgxMjIwLThjMDUxZmIyNTRiMTJjNjIyMzdmZDA3MTQxZWUwZTFjZjQwNGYxZGM5MzRmNzZlMWI5ZWUyOTkzMjE5Njg1NDg) <!-- GEN:chromium-version-badge -->[![Chromium version](https://img.shields.io/badge/chromium-86.0.4211.0-blue.svg?logo=google-chrome)](https://www.chromium.org/Home)<!-- GEN:stop --> <!-- GEN:firefox-version-badge -->[![Firefox version](https://img.shields.io/badge/firefox-78.0b5-blue.svg?logo=mozilla-firefox)](https://www.mozilla.org/en-US/firefox/new/)<!-- GEN:stop --> [![WebKit version](https://img.shields.io/badge/webkit-14.0-blue.svg?logo=safari)](https://webkit.org/)
3+
[![PyPI version](https://badge.fury.io/py/playwright.svg)](https://pypi.python.org/pypi/playwright/) [![Join Slack](https://img.shields.io/badge/join-slack-infomational)](https://join.slack.com/t/playwright/shared_invite/enQtOTEyMTUxMzgxMjIwLThjMDUxZmIyNTRiMTJjNjIyMzdmZDA3MTQxZWUwZTFjZjQwNGYxZGM5MzRmNzZlMWI5ZWUyOTkzMjE5Njg1NDg) <!-- GEN:chromium-version-badge -->[![Chromium version](https://img.shields.io/badge/chromium-86.0.4217.0-blue.svg?logo=google-chrome)](https://www.chromium.org/Home)<!-- GEN:stop --> <!-- GEN:firefox-version-badge -->[![Firefox version](https://img.shields.io/badge/firefox-78.0b5-blue.svg?logo=mozilla-firefox)](https://www.mozilla.org/en-US/firefox/new/)<!-- GEN:stop --> [![WebKit version](https://img.shields.io/badge/webkit-14.0-blue.svg?logo=safari)](https://webkit.org/)
44
[![Coverage Status](https://coveralls.io/repos/github/microsoft/playwright-python/badge.svg?branch=master)](https://coveralls.io/github/microsoft/playwright-python?branch=master)
55

66
##### [Docs](https://github.com/microsoft/playwright/blob/master/docs/README.md) | [API reference](https://github.com/microsoft/playwright/blob/master/docs/api.md)
@@ -9,7 +9,7 @@ Playwright is a Python library to automate [Chromium](https://www.chromium.org/H
99

1010
| | Linux | macOS | Windows |
1111
| :--- | :---: | :---: | :---: |
12-
| Chromium <!-- GEN:chromium-version -->86.0.4211.0<!-- GEN:stop --> ||||
12+
| Chromium <!-- GEN:chromium-version -->86.0.4217.0<!-- GEN:stop --> ||||
1313
| WebKit 14.0 ||||
1414
| Firefox <!-- GEN:firefox-version -->78.0b5<!-- GEN:stop --> ||||
1515

driver/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
},
1414
"license": "Apache-2.0",
1515
"dependencies": {
16-
"playwright": "1.2.0-next.1595625808301"
16+
"playwright": "1.2.0-next.1596080705875"
1717
},
1818
"devDependencies": {
1919
"pkg": "^4.4.9"

playwright/accessibility.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ def _ax_node_from_protocol(axNode: Dict[str, Any]) -> Dict[str, Any]:
5555
class Accessibility:
5656
def __init__(self, channel: Channel) -> None:
5757
self._channel = channel
58-
self._loop = channel._scope._loop
58+
self._loop = channel._connection._loop
5959

6060
async def snapshot(
6161
self, interestingOnly: bool = True, root: ElementHandle = None
6262
) -> Optional[Dict[str, Any]]:
63-
root = root._channel if root else None
64-
result = await self._channel.send(
65-
"accessibilitySnapshot", dict(root=root, interestingOnly=interestingOnly),
66-
)
63+
params = {"interestingOnly": interestingOnly}
64+
if root:
65+
params["root"] = root._channel
66+
result = await self._channel.send("accessibilitySnapshot", params,)
6767
return _ax_node_from_protocol(result) if result else None

playwright/browser.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from typing import Dict, List, Union
1818

1919
from playwright.browser_context import BrowserContext
20-
from playwright.connection import ChannelOwner, ConnectionScope, from_channel
20+
from playwright.connection import ChannelOwner, from_channel
2121
from playwright.helper import ColorScheme, locals_to_params
2222
from playwright.network import serialize_headers
2323
from playwright.page import Page
@@ -32,8 +32,10 @@ class Browser(ChannelOwner):
3232

3333
Events = SimpleNamespace(Disconnected="disconnected",)
3434

35-
def __init__(self, scope: ConnectionScope, guid: str, initializer: Dict) -> None:
36-
super().__init__(scope, guid, initializer, True)
35+
def __init__(
36+
self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
37+
) -> None:
38+
super().__init__(parent, type, guid, initializer)
3739
self._is_connected = True
3840
self._is_closed_or_closing = False
3941

@@ -44,7 +46,6 @@ def _on_close(self) -> None:
4446
self._is_connected = False
4547
self.emit(Browser.Events.Disconnected)
4648
self._is_closed_or_closing = True
47-
self._scope.dispose()
4849

4950
@property
5051
def contexts(self) -> List[BrowserContext]:
@@ -75,7 +76,7 @@ async def newContext(
7576
) -> BrowserContext:
7677
params = locals_to_params(locals())
7778
if viewport == 0:
78-
params["viewport"] = None
79+
del params["viewport"]
7980
params["noDefaultViewport"] = True
8081
if extraHTTPHeaders:
8182
params["extraHTTPHeaders"] = serialize_headers(extraHTTPHeaders)

playwright/browser_context.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from types import SimpleNamespace
1717
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Union
1818

19-
from playwright.connection import ChannelOwner, ConnectionScope, from_channel
19+
from playwright.connection import ChannelOwner, from_channel
2020
from playwright.event_context_manager import EventContextManagerImpl
2121
from playwright.helper import (
2222
Cookie,
@@ -41,8 +41,10 @@ class BrowserContext(ChannelOwner):
4141

4242
Events = SimpleNamespace(Close="close", Page="page",)
4343

44-
def __init__(self, scope: ConnectionScope, guid: str, initializer: Dict) -> None:
45-
super().__init__(scope, guid, initializer, True)
44+
def __init__(
45+
self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
46+
) -> None:
47+
super().__init__(parent, type, guid, initializer)
4648
self._pages: List[Page] = []
4749
self._routes: List[RouteHandlerEntry] = []
4850
self._bindings: Dict[str, Any] = {}
@@ -205,7 +207,6 @@ def _on_close(self) -> None:
205207
pending_event.reject(False, "Context")
206208

207209
self.emit(BrowserContext.Events.Close)
208-
self._scope.dispose()
209210

210211
async def close(self) -> None:
211212
if self._is_closed_or_closing:

playwright/browser_server.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@
1515
from types import SimpleNamespace
1616
from typing import Dict
1717

18-
from playwright.connection import ChannelOwner, ConnectionScope
18+
from playwright.connection import ChannelOwner
1919

2020

2121
class BrowserServer(ChannelOwner):
2222

2323
Events = SimpleNamespace(Close="close",)
2424

25-
def __init__(self, scope: ConnectionScope, guid: str, initializer: Dict) -> None:
26-
super().__init__(scope, guid, initializer)
25+
def __init__(
26+
self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
27+
) -> None:
28+
super().__init__(parent, type, guid, initializer)
2729
self._channel.on("close", lambda _: self.emit(BrowserServer.Events.Close))
2830

2931
@property

playwright/browser_type.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616

1717
from playwright.browser import Browser
1818
from playwright.browser_context import BrowserContext
19-
from playwright.connection import ChannelOwner, ConnectionScope, from_channel
19+
from playwright.connection import ChannelOwner, from_channel
2020
from playwright.helper import ColorScheme, locals_to_params, not_installed_error
2121

2222

2323
class BrowserType(ChannelOwner):
24-
def __init__(self, scope: ConnectionScope, guid: str, initializer: Dict) -> None:
25-
super().__init__(scope, guid, initializer, True)
24+
def __init__(
25+
self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
26+
) -> None:
27+
super().__init__(parent, type, guid, initializer)
2628

2729
@property
2830
def name(self) -> str:

playwright/connection.py

Lines changed: 51 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import asyncio
1616
import sys
1717
import traceback
18-
from typing import Any, Callable, Dict, List, Optional
18+
from typing import Any, Callable, Dict, Optional, Union
1919

2020
from greenlet import greenlet
2121
from pyee import BaseEventEmitter
@@ -26,16 +26,17 @@
2626

2727

2828
class Channel(BaseEventEmitter):
29-
def __init__(self, scope: "ConnectionScope", guid: str) -> None:
29+
def __init__(self, connection: "Connection", guid: str) -> None:
3030
super().__init__()
31-
self._scope: ConnectionScope = scope
31+
self._connection: Connection = connection
3232
self._guid = guid
3333
self._object: Optional[ChannelOwner] = None
3434

3535
async def send(self, method: str, params: dict = None) -> Any:
3636
if params is None:
3737
params = {}
38-
result = await self._scope.send_message_to_server(self._guid, method, params)
38+
callback = self._connection._send_message_to_server(self._guid, method, params)
39+
result = await callback.future
3940
# Protocol now has named return values, assume result is one level deeper unless
4041
# there is explicit ambiguity.
4142
if not result:
@@ -50,79 +51,46 @@ async def send(self, method: str, params: dict = None) -> Any:
5051
def send_no_reply(self, method: str, params: dict = None) -> None:
5152
if params is None:
5253
params = {}
53-
self._scope.send_message_to_server_no_reply(self._guid, method, params)
54+
self._connection._send_message_to_server(self._guid, method, params)
5455

5556

5657
class ChannelOwner(BaseEventEmitter):
5758
def __init__(
5859
self,
59-
scope: "ConnectionScope",
60+
parent: Union["ChannelOwner", "Connection"],
61+
type: str,
6062
guid: str,
6163
initializer: Dict,
62-
is_scope: bool = False,
6364
) -> None:
6465
super().__init__()
66+
self._loop: asyncio.AbstractEventLoop = parent._loop
67+
self._type = type
6568
self._guid = guid
66-
self._scope = scope.create_child(guid) if is_scope else scope
67-
self._loop = self._scope._loop
68-
self._channel = Channel(self._scope, guid)
69+
self._connection: Connection = parent._connection if isinstance(
70+
parent, ChannelOwner
71+
) else parent
72+
self._parent: Optional[ChannelOwner] = parent if isinstance(
73+
parent, ChannelOwner
74+
) else None
75+
self._objects: Dict[str, "ChannelOwner"] = {}
76+
self._channel = Channel(self._connection, guid)
6977
self._channel._object = self
7078
self._initializer = initializer
7179

72-
73-
class ConnectionScope:
74-
def __init__(
75-
self, connection: "Connection", guid: str, parent: Optional["ConnectionScope"]
76-
) -> None:
77-
self._connection: "Connection" = connection
78-
self._loop: asyncio.AbstractEventLoop = connection._loop
79-
self._guid: str = guid
80-
self._children: List["ConnectionScope"] = []
81-
self._objects: Dict[str, ChannelOwner] = {}
82-
self._parent = parent
83-
84-
def create_child(self, guid: str) -> "ConnectionScope":
85-
scope = self._connection.create_scope(guid, self)
86-
self._children.append(scope)
87-
return scope
88-
89-
def dispose(self) -> None:
90-
# Take care of hierarchy.
91-
for child in self._children:
92-
child.dispose()
93-
self._children.clear()
94-
95-
# Delete self from scopes and objects.
96-
self._connection._scopes.pop(self._guid)
97-
self._connection._objects.pop(self._guid)
98-
99-
# Delete all of the objects from connection.
100-
for guid in self._objects:
101-
self._connection._objects.pop(guid)
102-
103-
# Clean up from parent.
80+
self._connection._objects[guid] = self
10481
if self._parent:
105-
self._parent._objects.pop(self._guid)
106-
self._parent._children.remove(self)
82+
self._parent._objects[guid] = self
10783

108-
async def send_message_to_server(self, guid: str, method: str, params: Dict) -> Any:
109-
callback = self._connection._send_message_to_server(guid, method, params)
110-
return await callback.future
111-
112-
def send_message_to_server_no_reply(
113-
self, guid: str, method: str, params: Dict
114-
) -> Any:
115-
self._connection._send_message_to_server(guid, method, params)
84+
def _dispose(self) -> None:
85+
# Clean up from parent and connection.
86+
if self._parent:
87+
del self._parent._objects[self._guid]
88+
del self._connection._objects[self._guid]
11689

117-
def create_remote_object(self, type: str, guid: str, initializer: Dict) -> Any:
118-
result: ChannelOwner
119-
initializer = self._connection._replace_guids_with_channels(initializer)
120-
result = self._connection._object_factory(self, type, guid, initializer)
121-
self._connection._objects[guid] = result
122-
self._objects[guid] = result
123-
if guid in self._connection._waiting_for_object:
124-
self._connection._waiting_for_object.pop(guid)(result)
125-
return result
90+
# Dispose all children.
91+
for object in list(self._objects.values()):
92+
object._dispose()
93+
self._objects.clear()
12694

12795

12896
class ProtocolCallback:
@@ -131,6 +99,11 @@ def __init__(self, loop: asyncio.AbstractEventLoop) -> None:
13199
self.future = loop.create_future()
132100

133101

102+
class RootChannelOwner(ChannelOwner):
103+
def __init__(self, connection: "Connection") -> None:
104+
super().__init__(connection, "", "", {})
105+
106+
134107
class Connection:
135108
def __init__(
136109
self,
@@ -145,9 +118,8 @@ def __init__(
145118
self._last_id = 0
146119
self._loop = loop
147120
self._objects: Dict[str, ChannelOwner] = {}
148-
self._scopes: Dict[str, ConnectionScope] = {}
149121
self._callbacks: Dict[int, ProtocolCallback] = {}
150-
self._root_scope = self.create_scope("", None)
122+
self._root_object = RootChannelOwner(self)
151123
self._object_factory = object_factory
152124
self._is_sync = False
153125

@@ -215,11 +187,14 @@ def _dispatch(self, msg: ParsedMessagePayload) -> None:
215187
method = msg.get("method")
216188
params = msg["params"]
217189
if method == "__create__":
218-
scope = self._scopes[guid]
219-
scope.create_remote_object(
220-
params["type"], params["guid"], params["initializer"]
190+
parent = self._objects[guid]
191+
self._create_remote_object(
192+
parent, params["type"], params["guid"], params["initializer"]
221193
)
222194
return
195+
if method == "__dispose__":
196+
self._objects[guid]._dispose()
197+
return
223198

224199
object = self._objects[guid]
225200
try:
@@ -235,6 +210,16 @@ def _dispatch(self, msg: ParsedMessagePayload) -> None:
235210
"".join(traceback.format_exception(*sys.exc_info())),
236211
)
237212

213+
def _create_remote_object(
214+
self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
215+
) -> Any:
216+
result: ChannelOwner
217+
initializer = self._replace_guids_with_channels(initializer)
218+
result = self._object_factory(parent, type, guid, initializer)
219+
if guid in self._waiting_for_object:
220+
self._waiting_for_object.pop(guid)(result)
221+
return result
222+
238223
def _replace_channels_with_guids(self, payload: Any) -> Any:
239224
if payload is None:
240225
return payload
@@ -263,13 +248,6 @@ def _replace_guids_with_channels(self, payload: Any) -> Any:
263248
return result
264249
return payload
265250

266-
def create_scope(
267-
self, guid: str, parent: Optional[ConnectionScope]
268-
) -> ConnectionScope:
269-
scope = ConnectionScope(self, guid, parent)
270-
self._scopes[guid] = scope
271-
return scope
272-
273251

274252
def from_channel(channel: Channel) -> Any:
275253
return channel._object

playwright/console_message.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@
1414

1515
from typing import Dict, List
1616

17-
from playwright.connection import ChannelOwner, ConnectionScope, from_channel
17+
from playwright.connection import ChannelOwner, from_channel
1818
from playwright.helper import ConsoleMessageLocation
1919
from playwright.js_handle import JSHandle
2020

2121

2222
class ConsoleMessage(ChannelOwner):
23-
def __init__(self, scope: ConnectionScope, guid: str, initializer: Dict) -> None:
24-
super().__init__(scope, guid, initializer)
23+
def __init__(
24+
self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
25+
) -> None:
26+
super().__init__(parent, type, guid, initializer)
2527

2628
def __str__(self) -> str:
2729
return self.text

playwright/dialog.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414

1515
from typing import Dict
1616

17-
from playwright.connection import ChannelOwner, ConnectionScope
17+
from playwright.connection import ChannelOwner
1818
from playwright.helper import locals_to_params
1919

2020

2121
class Dialog(ChannelOwner):
22-
def __init__(self, scope: ConnectionScope, guid: str, initializer: Dict) -> None:
23-
super().__init__(scope, guid, initializer)
22+
def __init__(
23+
self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
24+
) -> None:
25+
super().__init__(parent, type, guid, initializer)
2426

2527
@property
2628
def type(self) -> str:

0 commit comments

Comments
 (0)