Skip to content

chore: better type annotation for channels #591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions playwright/_impl/_browser_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from playwright._impl._browser_context import BrowserContext
from playwright._impl._connection import ChannelOwner, from_channel
from playwright._impl._helper import (
BrowserChannel,
ColorScheme,
Env,
locals_to_params,
Expand Down Expand Up @@ -52,7 +53,7 @@ def executable_path(self) -> str:
async def launch(
self,
executablePath: Union[str, Path] = None,
channel: str = None,
channel: BrowserChannel = None,
args: List[str] = None,
ignoreDefaultArgs: Union[bool, List[str]] = None,
handleSIGINT: bool = None,
Expand Down Expand Up @@ -80,7 +81,7 @@ async def launch(
async def launch_persistent_context(
self,
userDataDir: Union[str, Path],
channel: str = None,
channel: BrowserChannel = None,
executablePath: Union[str, Path] = None,
args: List[str] = None,
ignoreDefaultArgs: Union[bool, List[str]] = None,
Expand Down
11 changes: 11 additions & 0 deletions playwright/_impl/_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@
KeyboardModifier = Literal["Alt", "Control", "Meta", "Shift"]
MouseButton = Literal["left", "middle", "right"]

BrowserChannel = Literal[
"chrome",
"chrome-beta",
"chrome-canary",
"chrome-dev",
"msedge",
"msedge-beta",
"msedge-canary",
"msedge-dev",
]


class ErrorPayload(TypedDict, total=False):
message: str
Expand Down
69 changes: 39 additions & 30 deletions playwright/async_api/_generated.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ def resource_type(self) -> str:
following: `document`, `stylesheet`, `image`, `media`, `font`, `script`, `texttrack`, `xhr`, `fetch`, `eventsource`,
`websocket`, `manifest`, `other`.

> NOTE: The resource types are available as constants in [ResourceTypes].

Returns
-------
str
Expand Down Expand Up @@ -8641,11 +8639,14 @@ async def new_context(
option to work. If all contexts override the proxy, global proxy will be never used and can be any string, for example
`launch({ proxy: { server: 'per-context' } })`.
record_har_path : Union[pathlib.Path, str, NoneType]
Path on the filesystem to write the HAR file to.
Enables [HAR](http://www.softwareishard.com/blog/har-12-spec) recording for all pages into the specified HAR file on the
filesystem. If not specified, the HAR is not recorded. Make sure to call `browser_context.close()` for the HAR to
be saved.
record_har_omit_content : Union[bool, NoneType]
Optional setting to control whether to omit request content from the HAR. Defaults to `false`.
record_video_dir : Union[pathlib.Path, str, NoneType]
Path to the directory to put videos into.
Enables video recording for all pages into the specified directory. If not specified videos are not recorded. Make sure
to call `browser_context.close()` for videos to be saved.
record_video_size : Union[{width: int, height: int}, NoneType]
Dimensions of the recorded videos. If not specified the size will be equal to `viewport` scaled down to fit into
800x800. If `viewport` is not configured explicitly the video size defaults to 800x450. Actual picture of each page will
Expand Down Expand Up @@ -8778,11 +8779,14 @@ async def new_page(
option to work. If all contexts override the proxy, global proxy will be never used and can be any string, for example
`launch({ proxy: { server: 'per-context' } })`.
record_har_path : Union[pathlib.Path, str, NoneType]
Path on the filesystem to write the HAR file to.
Enables [HAR](http://www.softwareishard.com/blog/har-12-spec) recording for all pages into the specified HAR file on the
filesystem. If not specified, the HAR is not recorded. Make sure to call `browser_context.close()` for the HAR to
be saved.
record_har_omit_content : Union[bool, NoneType]
Optional setting to control whether to omit request content from the HAR. Defaults to `false`.
record_video_dir : Union[pathlib.Path, str, NoneType]
Path to the directory to put videos into.
Enables video recording for all pages into the specified directory. If not specified videos are not recorded. Make sure
to call `browser_context.close()` for videos to be saved.
record_video_size : Union[{width: int, height: int}, NoneType]
Dimensions of the recorded videos. If not specified the size will be equal to `viewport` scaled down to fit into
800x800. If `viewport` is not configured explicitly the video size defaults to 800x450. Actual picture of each page will
Expand Down Expand Up @@ -8882,7 +8886,16 @@ async def launch(
self,
*,
executable_path: typing.Union[str, pathlib.Path] = None,
channel: str = None,
channel: Literal[
"chrome",
"chrome-beta",
"chrome-canary",
"chrome-dev",
"msedge",
"msedge-beta",
"msedge-canary",
"msedge-dev",
] = None,
args: typing.List[str] = None,
ignore_default_args: typing.Union[bool, typing.List[str]] = None,
handle_sigint: bool = None,
Expand Down Expand Up @@ -8933,16 +8946,8 @@ async def launch(
Path to a browser executable to run instead of the bundled one. If `executablePath` is a relative path, then it is
resolved relative to the current working directory. Note that Playwright only works with the bundled Chromium, Firefox
or WebKit, use at your own risk.
channel : Union[str, NoneType]
Chromium distribution channel, one of
- chrome
- chrome-beta
- chrome-dev
- chrome-canary
- msedge
- msedge-beta
- msedge-dev
- msedge-canary
channel : Union["chrome", "chrome-beta", "chrome-canary", "chrome-dev", "msedge", "msedge-beta", "msedge-canary", "msedge-dev", NoneType]
Browser distribution channel.
args : Union[List[str], NoneType]
Additional arguments to pass to the browser instance. The list of Chromium flags can be found
[here](http://peter.sh/experiments/chromium-command-line-switches/).
Expand Down Expand Up @@ -9014,7 +9019,16 @@ async def launch_persistent_context(
self,
user_data_dir: typing.Union[str, pathlib.Path],
*,
channel: str = None,
channel: Literal[
"chrome",
"chrome-beta",
"chrome-canary",
"chrome-dev",
"msedge",
"msedge-beta",
"msedge-canary",
"msedge-dev",
] = None,
executable_path: typing.Union[str, pathlib.Path] = None,
args: typing.List[str] = None,
ignore_default_args: typing.Union[bool, typing.List[str]] = None,
Expand Down Expand Up @@ -9066,16 +9080,8 @@ async def launch_persistent_context(
[Chromium](https://chromium.googlesource.com/chromium/src/+/master/docs/user_data_dir.md#introduction) and
[Firefox](https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options#User_Profile). Note that Chromium's user
data directory is the **parent** directory of the "Profile Path" seen at `chrome://version`.
channel : Union[str, NoneType]
Chromium distribution channel, one of
- chrome
- chrome-beta
- chrome-dev
- chrome-canary
- msedge
- msedge-beta
- msedge-dev
- msedge-canary
channel : Union["chrome", "chrome-beta", "chrome-canary", "chrome-dev", "msedge", "msedge-beta", "msedge-canary", "msedge-dev", NoneType]
Browser distribution channel.
executable_path : Union[pathlib.Path, str, NoneType]
Path to a browser executable to run instead of the bundled one. If `executablePath` is a relative path, then it is
resolved relative to the current working directory. **BEWARE**: Playwright is only guaranteed to work with the bundled
Expand Down Expand Up @@ -9157,11 +9163,14 @@ async def launch_persistent_context(
chromium_sandbox : Union[bool, NoneType]
Enable Chromium sandboxing. Defaults to `true`.
record_har_path : Union[pathlib.Path, str, NoneType]
Path on the filesystem to write the HAR file to.
Enables [HAR](http://www.softwareishard.com/blog/har-12-spec) recording for all pages into the specified HAR file on the
filesystem. If not specified, the HAR is not recorded. Make sure to call `browser_context.close()` for the HAR to
be saved.
record_har_omit_content : Union[bool, NoneType]
Optional setting to control whether to omit request content from the HAR. Defaults to `false`.
record_video_dir : Union[pathlib.Path, str, NoneType]
Path to the directory to put videos into.
Enables video recording for all pages into the specified directory. If not specified videos are not recorded. Make sure
to call `browser_context.close()` for videos to be saved.
record_video_size : Union[{width: int, height: int}, NoneType]
Dimensions of the recorded videos. If not specified the size will be equal to `viewport` scaled down to fit into
800x800. If `viewport` is not configured explicitly the video size defaults to 800x450. Actual picture of each page will
Expand Down
69 changes: 39 additions & 30 deletions playwright/sync_api/_generated.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ def resource_type(self) -> str:
following: `document`, `stylesheet`, `image`, `media`, `font`, `script`, `texttrack`, `xhr`, `fetch`, `eventsource`,
`websocket`, `manifest`, `other`.

> NOTE: The resource types are available as constants in [ResourceTypes].

Returns
-------
str
Expand Down Expand Up @@ -8587,11 +8585,14 @@ def new_context(
option to work. If all contexts override the proxy, global proxy will be never used and can be any string, for example
`launch({ proxy: { server: 'per-context' } })`.
record_har_path : Union[pathlib.Path, str, NoneType]
Path on the filesystem to write the HAR file to.
Enables [HAR](http://www.softwareishard.com/blog/har-12-spec) recording for all pages into the specified HAR file on the
filesystem. If not specified, the HAR is not recorded. Make sure to call `browser_context.close()` for the HAR to
be saved.
record_har_omit_content : Union[bool, NoneType]
Optional setting to control whether to omit request content from the HAR. Defaults to `false`.
record_video_dir : Union[pathlib.Path, str, NoneType]
Path to the directory to put videos into.
Enables video recording for all pages into the specified directory. If not specified videos are not recorded. Make sure
to call `browser_context.close()` for videos to be saved.
record_video_size : Union[{width: int, height: int}, NoneType]
Dimensions of the recorded videos. If not specified the size will be equal to `viewport` scaled down to fit into
800x800. If `viewport` is not configured explicitly the video size defaults to 800x450. Actual picture of each page will
Expand Down Expand Up @@ -8724,11 +8725,14 @@ def new_page(
option to work. If all contexts override the proxy, global proxy will be never used and can be any string, for example
`launch({ proxy: { server: 'per-context' } })`.
record_har_path : Union[pathlib.Path, str, NoneType]
Path on the filesystem to write the HAR file to.
Enables [HAR](http://www.softwareishard.com/blog/har-12-spec) recording for all pages into the specified HAR file on the
filesystem. If not specified, the HAR is not recorded. Make sure to call `browser_context.close()` for the HAR to
be saved.
record_har_omit_content : Union[bool, NoneType]
Optional setting to control whether to omit request content from the HAR. Defaults to `false`.
record_video_dir : Union[pathlib.Path, str, NoneType]
Path to the directory to put videos into.
Enables video recording for all pages into the specified directory. If not specified videos are not recorded. Make sure
to call `browser_context.close()` for videos to be saved.
record_video_size : Union[{width: int, height: int}, NoneType]
Dimensions of the recorded videos. If not specified the size will be equal to `viewport` scaled down to fit into
800x800. If `viewport` is not configured explicitly the video size defaults to 800x450. Actual picture of each page will
Expand Down Expand Up @@ -8828,7 +8832,16 @@ def launch(
self,
*,
executable_path: typing.Union[str, pathlib.Path] = None,
channel: str = None,
channel: Literal[
"chrome",
"chrome-beta",
"chrome-canary",
"chrome-dev",
"msedge",
"msedge-beta",
"msedge-canary",
"msedge-dev",
] = None,
args: typing.List[str] = None,
ignore_default_args: typing.Union[bool, typing.List[str]] = None,
handle_sigint: bool = None,
Expand Down Expand Up @@ -8879,16 +8892,8 @@ def launch(
Path to a browser executable to run instead of the bundled one. If `executablePath` is a relative path, then it is
resolved relative to the current working directory. Note that Playwright only works with the bundled Chromium, Firefox
or WebKit, use at your own risk.
channel : Union[str, NoneType]
Chromium distribution channel, one of
- chrome
- chrome-beta
- chrome-dev
- chrome-canary
- msedge
- msedge-beta
- msedge-dev
- msedge-canary
channel : Union["chrome", "chrome-beta", "chrome-canary", "chrome-dev", "msedge", "msedge-beta", "msedge-canary", "msedge-dev", NoneType]
Browser distribution channel.
args : Union[List[str], NoneType]
Additional arguments to pass to the browser instance. The list of Chromium flags can be found
[here](http://peter.sh/experiments/chromium-command-line-switches/).
Expand Down Expand Up @@ -8960,7 +8965,16 @@ def launch_persistent_context(
self,
user_data_dir: typing.Union[str, pathlib.Path],
*,
channel: str = None,
channel: Literal[
"chrome",
"chrome-beta",
"chrome-canary",
"chrome-dev",
"msedge",
"msedge-beta",
"msedge-canary",
"msedge-dev",
] = None,
executable_path: typing.Union[str, pathlib.Path] = None,
args: typing.List[str] = None,
ignore_default_args: typing.Union[bool, typing.List[str]] = None,
Expand Down Expand Up @@ -9012,16 +9026,8 @@ def launch_persistent_context(
[Chromium](https://chromium.googlesource.com/chromium/src/+/master/docs/user_data_dir.md#introduction) and
[Firefox](https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options#User_Profile). Note that Chromium's user
data directory is the **parent** directory of the "Profile Path" seen at `chrome://version`.
channel : Union[str, NoneType]
Chromium distribution channel, one of
- chrome
- chrome-beta
- chrome-dev
- chrome-canary
- msedge
- msedge-beta
- msedge-dev
- msedge-canary
channel : Union["chrome", "chrome-beta", "chrome-canary", "chrome-dev", "msedge", "msedge-beta", "msedge-canary", "msedge-dev", NoneType]
Browser distribution channel.
executable_path : Union[pathlib.Path, str, NoneType]
Path to a browser executable to run instead of the bundled one. If `executablePath` is a relative path, then it is
resolved relative to the current working directory. **BEWARE**: Playwright is only guaranteed to work with the bundled
Expand Down Expand Up @@ -9103,11 +9109,14 @@ def launch_persistent_context(
chromium_sandbox : Union[bool, NoneType]
Enable Chromium sandboxing. Defaults to `true`.
record_har_path : Union[pathlib.Path, str, NoneType]
Path on the filesystem to write the HAR file to.
Enables [HAR](http://www.softwareishard.com/blog/har-12-spec) recording for all pages into the specified HAR file on the
filesystem. If not specified, the HAR is not recorded. Make sure to call `browser_context.close()` for the HAR to
be saved.
record_har_omit_content : Union[bool, NoneType]
Optional setting to control whether to omit request content from the HAR. Defaults to `false`.
record_video_dir : Union[pathlib.Path, str, NoneType]
Path to the directory to put videos into.
Enables video recording for all pages into the specified directory. If not specified videos are not recorded. Make sure
to call `browser_context.close()` for videos to be saved.
record_video_size : Union[{width: int, height: int}, NoneType]
Dimensions of the recorded videos. If not specified the size will be equal to `viewport` scaled down to fit into
800x800. If `viewport` is not configured explicitly the video size defaults to 800x450. Actual picture of each page will
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from auditwheel.wheeltools import InWheel
from wheel.bdist_wheel import bdist_wheel as BDistWheelCommand

driver_version = "1.10.0-next-1616094973000"
driver_version = "1.10.0-next-1616530863000"


def extractall(zip: zipfile.ZipFile, path: str) -> None:
Expand Down