Skip to content

Commit 47d42d8

Browse files
authored
chore: roll to ToT driver (microsoft#420)
1 parent fa7d908 commit 47d42d8

35 files changed

+1157
-1155
lines changed

playwright/_impl/_api_structures.py

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
import sys
16-
from typing import List, Optional
16+
from typing import List, Optional, Union
1717

1818
if sys.version_info >= (3, 8): # pragma: no cover
1919
from typing import Literal, TypedDict
@@ -40,6 +40,24 @@ class Cookie(TypedDict, total=False):
4040
sameSite: Optional[Literal["Lax", "None", "Strict"]]
4141

4242

43+
class FloatRect(TypedDict):
44+
x: float
45+
y: float
46+
width: float
47+
height: float
48+
49+
50+
class Geolocation(TypedDict, total=False):
51+
latitude: float
52+
longitude: float
53+
accuracy: Optional[float]
54+
55+
56+
class HttpCredentials(TypedDict):
57+
username: str
58+
password: str
59+
60+
4361
class LocalStorageEntry(TypedDict):
4462
name: str
4563
value: str
@@ -50,6 +68,25 @@ class OriginState(TypedDict):
5068
localStorage: List[LocalStorageEntry]
5169

5270

71+
class PdfMargins(TypedDict, total=False):
72+
top: Optional[Union[str, float]]
73+
right: Optional[Union[str, float]]
74+
bottom: Optional[Union[str, float]]
75+
left: Optional[Union[str, float]]
76+
77+
78+
class Position(TypedDict):
79+
x: float
80+
y: float
81+
82+
83+
class ProxySettings(TypedDict, total=False):
84+
server: str
85+
bypass: Optional[str]
86+
username: Optional[str]
87+
password: Optional[str]
88+
89+
5390
class StorageState(TypedDict, total=False):
5491
cookies: Optional[List[Cookie]]
5592
origins: Optional[List[OriginState]]
@@ -65,3 +102,20 @@ class ResourceTiming(TypedDict):
65102
requestStart: float
66103
responseStart: float
67104
responseEnd: float
105+
106+
107+
class ViewportSize(TypedDict):
108+
width: int
109+
height: int
110+
111+
112+
class SourceLocation(TypedDict):
113+
url: str
114+
lineNumber: int
115+
columnNumber: int
116+
117+
118+
class FilePayload(TypedDict):
119+
name: str
120+
mimeType: str
121+
buffer: bytes

playwright/_impl/_api_types.py

Lines changed: 0 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import sys
16-
from typing import Any, Dict, Optional, Tuple, Union
17-
18-
if sys.version_info >= (3, 8): # pragma: no cover
19-
from typing import TypedDict
20-
else: # pragma: no cover
21-
from typing_extensions import TypedDict
22-
2315
# These are types that we use in the API. They are public and are a part of the
2416
# stable API.
2517

@@ -33,122 +25,3 @@ def __init__(self, message: str, stack: str = None) -> None:
3325

3426
class TimeoutError(Error):
3527
pass
36-
37-
38-
class ApiType:
39-
def __eq__(self, other: Any) -> bool:
40-
if isinstance(other, self.__class__):
41-
return self.__dict__ == other.__dict__
42-
else:
43-
return False
44-
45-
def _to_json(self) -> Dict:
46-
return filter_out_none(self.__dict__)
47-
48-
49-
class FilePayload(ApiType):
50-
name: str
51-
mime_type: str
52-
buffer: bytes
53-
54-
def __init__(self, name: str, mime_type: str, buffer: bytes):
55-
self.name = name
56-
self.mime_type = mime_type
57-
self.buffer = buffer
58-
59-
60-
class FloatRect(ApiType):
61-
x: float
62-
y: float
63-
width: float
64-
height: float
65-
66-
@classmethod
67-
def _parse(cls, dict: Optional[Dict]) -> Optional["FloatRect"]:
68-
if not dict:
69-
return None
70-
return FloatRect(dict["x"], dict["y"], dict["width"], dict["height"])
71-
72-
def __init__(self, x: float, y: float, width: float, height: float):
73-
self.x = x
74-
self.y = y
75-
self.width = width
76-
self.height = height
77-
78-
79-
class DeviceDescriptor(TypedDict):
80-
user_agent: Optional[str]
81-
viewport: Optional[Tuple[int, int]]
82-
device_scale_factor: Optional[int]
83-
is_mobile: Optional[bool]
84-
has_touch: Optional[bool]
85-
86-
87-
class Geolocation(ApiType):
88-
latitude: float
89-
longitude: float
90-
accuracy: Optional[float]
91-
92-
def __init__(self, latitude: float, longitude: float, accuracy: float = None):
93-
self.latitude = latitude
94-
self.longitude = longitude
95-
self.accuracy = accuracy
96-
97-
98-
class PdfMargins(ApiType):
99-
top: Optional[Union[str, float]]
100-
right: Optional[Union[str, float]]
101-
bottom: Optional[Union[str, float]]
102-
left: Optional[Union[str, float]]
103-
104-
def __init__(
105-
self,
106-
top: Union[str, float],
107-
right: Union[str, float],
108-
bottom: Union[str, float],
109-
left: Union[str, float],
110-
):
111-
self.top = top
112-
self.right = right
113-
self.bottom = bottom
114-
self.left = left
115-
116-
117-
class ProxySettings(ApiType):
118-
server: str
119-
bypass: Optional[str]
120-
username: Optional[str]
121-
password: Optional[str]
122-
123-
def __init__(
124-
self,
125-
server: str,
126-
bypass: str = None,
127-
username: str = None,
128-
password: str = None,
129-
):
130-
self.server = server
131-
self.bypass = bypass
132-
self.username = username
133-
self.password = password
134-
135-
136-
class SourceLocation(ApiType):
137-
url: str
138-
line_number: int
139-
column_number: int
140-
141-
def __init__(self, url: str, line_number: int, column_number: int):
142-
self.url = url
143-
self.line_number = line_number
144-
self.column_number = column_number
145-
146-
147-
def filter_out_none(args: Dict) -> Any:
148-
copy = {}
149-
for key in args:
150-
if key == "self":
151-
continue
152-
if args[key] is not None:
153-
copy[key] = args[key]
154-
return copy

playwright/_impl/_browser.py

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,23 @@
1313
# limitations under the License.
1414

1515
import json
16-
import sys
1716
from pathlib import Path
1817
from types import SimpleNamespace
19-
from typing import TYPE_CHECKING, Dict, List, Tuple, Union
20-
21-
from playwright._impl._api_structures import StorageState
22-
from playwright._impl._api_types import Geolocation, ProxySettings
18+
from typing import TYPE_CHECKING, Dict, List, Union
19+
20+
from playwright._impl._api_structures import (
21+
Geolocation,
22+
HttpCredentials,
23+
ProxySettings,
24+
StorageState,
25+
ViewportSize,
26+
)
2327
from playwright._impl._browser_context import BrowserContext
2428
from playwright._impl._connection import ChannelOwner, from_channel
2529
from playwright._impl._helper import ColorScheme, is_safe_close_error, locals_to_params
2630
from playwright._impl._network import serialize_headers
2731
from playwright._impl._page import Page
2832

29-
if sys.version_info >= (3, 8): # pragma: no cover
30-
from typing import Literal
31-
else: # pragma: no cover
32-
from typing_extensions import Literal
33-
3433
if TYPE_CHECKING: # pragma: no cover
3534
from playwright._impl._browser_type import BrowserType
3635

@@ -66,7 +65,8 @@ def is_connected(self) -> bool:
6665

6766
async def new_context(
6867
self,
69-
viewport: Union[Tuple[int, int], Literal[0]] = None,
68+
viewport: ViewportSize = None,
69+
noViewport: bool = None,
7070
ignoreHTTPSErrors: bool = None,
7171
javaScriptEnabled: bool = None,
7272
bypassCSP: bool = None,
@@ -77,7 +77,7 @@ async def new_context(
7777
permissions: List[str] = None,
7878
extraHTTPHeaders: Dict[str, str] = None,
7979
offline: bool = None,
80-
httpCredentials: Tuple[str, str] = None,
80+
httpCredentials: HttpCredentials = None,
8181
deviceScaleFactor: float = None,
8282
isMobile: bool = None,
8383
hasTouch: bool = None,
@@ -88,7 +88,7 @@ async def new_context(
8888
recordHarPath: Union[Path, str] = None,
8989
recordHarOmitContent: bool = None,
9090
recordVideoDir: Union[Path, str] = None,
91-
recordVideoSize: Tuple[int, int] = None,
91+
recordVideoSize: ViewportSize = None,
9292
storageState: Union[StorageState, str, Path] = None,
9393
) -> BrowserContext:
9494
params = locals_to_params(locals())
@@ -103,7 +103,8 @@ async def new_context(
103103

104104
async def new_page(
105105
self,
106-
viewport: Union[Tuple[int, int], Literal[0]] = None,
106+
viewport: ViewportSize = None,
107+
noViewport: bool = None,
107108
ignoreHTTPSErrors: bool = None,
108109
javaScriptEnabled: bool = None,
109110
bypassCSP: bool = None,
@@ -114,7 +115,7 @@ async def new_page(
114115
permissions: List[str] = None,
115116
extraHTTPHeaders: Dict[str, str] = None,
116117
offline: bool = None,
117-
httpCredentials: Tuple[str, str] = None,
118+
httpCredentials: HttpCredentials = None,
118119
deviceScaleFactor: float = None,
119120
isMobile: bool = None,
120121
hasTouch: bool = None,
@@ -125,7 +126,7 @@ async def new_page(
125126
recordHarPath: Union[Path, str] = None,
126127
recordHarOmitContent: bool = None,
127128
recordVideoDir: Union[Path, str] = None,
128-
recordVideoSize: Tuple[int, int] = None,
129+
recordVideoSize: ViewportSize = None,
129130
storageState: Union[StorageState, str, Path] = None,
130131
) -> Page:
131132
params = locals_to_params(locals())
@@ -151,8 +152,8 @@ def version(self) -> str:
151152

152153

153154
def normalize_context_params(params: Dict) -> None:
154-
if "viewport" in params and params["viewport"] == 0:
155-
del params["viewport"]
155+
if params.get("noViewport"):
156+
del params["noViewport"]
156157
params["noDefaultViewport"] = True
157158
if "defaultBrowserType" in params:
158159
del params["defaultBrowserType"]
@@ -167,10 +168,7 @@ def normalize_context_params(params: Dict) -> None:
167168
if "recordVideoDir" in params:
168169
params["recordVideo"] = {"dir": str(params["recordVideoDir"])}
169170
if "recordVideoSize" in params:
170-
params["recordVideo"]["size"] = {
171-
"width": params["recordVideoSize"][0],
172-
"height": params["recordVideoSize"][1],
173-
}
171+
params["recordVideo"]["size"] = params["recordVideoSize"]
174172
del params["recordVideoSize"]
175173
del params["recordVideoDir"]
176174
if "storageState" in params:

playwright/_impl/_browser_context.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from types import SimpleNamespace
2020
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Union, cast
2121

22-
from playwright._impl._api_structures import Cookie, StorageState
22+
from playwright._impl._api_structures import Cookie, Geolocation, StorageState
2323
from playwright._impl._api_types import Error
2424
from playwright._impl._connection import ChannelOwner, from_channel
2525
from playwright._impl._event_context_manager import EventContextManagerImpl
@@ -141,15 +141,8 @@ async def grant_permissions(
141141
async def clear_permissions(self) -> None:
142142
await self._channel.send("clearPermissions")
143143

144-
async def set_geolocation(
145-
self, latitude: float, longitude: float, accuracy: Optional[float]
146-
) -> None:
147-
await self._channel.send(
148-
"setGeolocation", {"geolocation": locals_to_params(locals())}
149-
)
150-
151-
async def reset_geolocation(self) -> None:
152-
await self._channel.send("setGeolocation", {})
144+
async def set_geolocation(self, geolocation: Geolocation = None) -> None:
145+
await self._channel.send("setGeolocation", locals_to_params(locals()))
153146

154147
async def set_extra_http_headers(self, headers: Dict[str, str]) -> None:
155148
await self._channel.send(

0 commit comments

Comments
 (0)