Skip to content

Commit 2343ff1

Browse files
authored
fix(types): added types for devices (microsoft#90)
1 parent 9e3d4bb commit 2343ff1

File tree

5 files changed

+23
-6
lines changed

5 files changed

+23
-6
lines changed

playwright/connection.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ class ConnectionScope:
7070
def __init__(
7171
self, connection: "Connection", guid: str, parent: Optional["ConnectionScope"]
7272
) -> None:
73-
self._connection = connection
74-
self._loop = connection._loop
75-
self._guid = guid
73+
self._connection: "Connection" = connection
74+
self._loop: asyncio.AbstractEventLoop = connection._loop
75+
self._guid: str = guid
7676
self._children: List["ConnectionScope"] = list()
7777
self._objects: Dict[str, ChannelOwner] = dict()
7878
self._parent = parent

playwright/helper.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,21 @@ class FrameNavigatedEvent(TypedDict):
117117
error: Optional[str]
118118

119119

120+
Size = TypedDict("Size", {"width": int, "height": int})
121+
122+
DeviceDescriptor = TypedDict(
123+
"DeviceDescriptor",
124+
{
125+
"userAgent": str,
126+
"viewport": Size,
127+
"deviceScaleFactor": int,
128+
"isMobile": bool,
129+
"hasTouch": bool,
130+
},
131+
)
132+
Devices = Dict[str, DeviceDescriptor]
133+
134+
120135
class URLMatcher:
121136
def __init__(self, match: URLMatch) -> None:
122137
self._callback: Optional[Callable[[str], bool]] = None

playwright/playwright.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from playwright.browser_type import BrowserType
1818
from playwright.connection import ChannelOwner, ConnectionScope, from_channel
19+
from playwright.helper import Devices
1920
from playwright.selectors import Selectors
2021

2122

@@ -24,7 +25,7 @@ class Playwright(ChannelOwner):
2425
firefox: BrowserType
2526
webkit: BrowserType
2627
selectors: Selectors
27-
devices: Dict
28+
devices: Devices
2829

2930
def __init__(self, scope: ConnectionScope, guid: str, initializer: Dict) -> None:
3031
super().__init__(scope, guid, initializer)

playwright/sync.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from playwright.frame import Frame as FrameAsync
3636
from playwright.helper import (
3737
ConsoleMessageLocation,
38+
DeviceDescriptor,
3839
Error,
3940
FilePayload,
4041
SelectOption,
@@ -2801,7 +2802,7 @@ def selectors(self) -> "Selectors":
28012802
return Selectors._from_async(self._async_obj.selectors)
28022803

28032804
@property
2804-
def devices(self) -> typing.Dict:
2805+
def devices(self) -> typing.Dict[str, DeviceDescriptor]:
28052806
return self._async_obj.devices
28062807

28072808

scripts/generate_sync_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ def main() -> None:
261261
from playwright.element_handle import ElementHandle as ElementHandleAsync
262262
from playwright.file_chooser import FileChooser as FileChooserAsync
263263
from playwright.frame import Frame as FrameAsync
264-
from playwright.helper import ConsoleMessageLocation, Error, FilePayload, SelectOption, Viewport
264+
from playwright.helper import ConsoleMessageLocation, Error, FilePayload, SelectOption, Viewport, DeviceDescriptor
265265
from playwright.input import Keyboard as KeyboardAsync, Mouse as MouseAsync
266266
from playwright.js_handle import JSHandle as JSHandleAsync
267267
from playwright.network import Request as RequestAsync, Response as ResponseAsync, Route as RouteAsync

0 commit comments

Comments
 (0)