Skip to content
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
4 changes: 2 additions & 2 deletions build_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

from playwright.path_utils import get_file_dirname

driver_version_64 = "0.160.0-next.1604373941495"
driver_version_32 = "0.160.0-next.1604373978475"
driver_version_64 = "0.160.0-next.1605227932803"
driver_version_32 = "0.160.0-next.1605227936643"


def driver_version(platform: str) -> str:
Expand Down
5 changes: 3 additions & 2 deletions buildbots/test-sync-generation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ function assert_script {
oldfile="playwright/$2"
echo "Testing $newfile against $oldfile"

python $1 > $newfile
if ! python $1 > $newfile; then
exit 1
fi

pre-commit run --files $newfile

cmp $oldfile $newfile
exit_code=$?
rm $newfile
return $exit_code
}

assert_script "scripts/generate_sync_api.py" "sync_api.py"
Expand Down
39 changes: 26 additions & 13 deletions playwright/async_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
PdfMargins,
ProxyServer,
RecordHarOptions,
RecordVideoOptions,
RequestFailure,
ResourceTiming,
SelectOption,
Expand Down Expand Up @@ -5839,6 +5840,7 @@ async def newContext(
videosPath: str = None,
videoSize: IntSize = None,
recordHar: RecordHarOptions = None,
recordVideo: RecordVideoOptions = None,
) -> "BrowserContext":
"""Browser.newContext

Expand Down Expand Up @@ -5882,11 +5884,13 @@ async def newContext(
proxy : Optional[{"server": str, "bypass": Optional[str], "username": Optional[str], "password": Optional[str]}]
Network proxy settings to use with this context. Note that browser needs to be launched with the global proxy for this 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' } })`.
videosPath : Optional[str]
Enables video recording for all pages to `videosPath` folder. If not specified, videos are not recorded. Make sure to await `browserContext.close` for videos to be saved.
**NOTE** Use `recordVideo` instead, it takes precedence over `videosPath`. Enables video recording for all pages to `videosPath` directory. If not specified, videos are not recorded. Make sure to await `browserContext.close` for videos to be saved.
videoSize : Optional[{"width": int, "height": int}]
Specifies dimensions of the automatically recorded video. Can only be used if `videosPath` is set. If not specified the size will be equal to `viewport`. If `viewport` is not configured explicitly the video size defaults to 1280x720. Actual picture of the page will be scaled down if necessary to fit specified size.
**NOTE** Use `recordVideo` instead, it takes precedence over `videoSize`. Specifies dimensions of the automatically recorded video. Can only be used if `videosPath` is set. If not specified the size will be equal to `viewport`. If `viewport` is not configured explicitly the video size defaults to 1280x720. Actual picture of the page will be scaled down if necessary to fit specified size.
recordHar : Optional[{"omitContent": Optional[bool], "path": str}]
Enables HAR recording for all pages into `har.path` file. If not specified, the HAR is not recorded. Make sure to await `browserContext.close` for the HAR to be saved.
Enables HAR recording for all pages into `recordHar.path` file. If not specified, the HAR is not recorded. Make sure to await `browserContext.close` for the HAR to be saved.
recordVideo : Optional[{"dir": str, "size": Optional[{"width": int, "height": int}]}]
Enables video recording for all pages into `recordVideo.dir` directory. If not specified videos are not recorded. Make sure to await `browserContext.close` for videos to be saved.

Returns
-------
Expand Down Expand Up @@ -5916,6 +5920,7 @@ async def newContext(
videosPath=videosPath,
videoSize=videoSize,
recordHar=recordHar,
recordVideo=recordVideo,
)
)

Expand Down Expand Up @@ -5943,6 +5948,7 @@ async def newPage(
videosPath: str = None,
videoSize: IntSize = None,
recordHar: RecordHarOptions = None,
recordVideo: RecordVideoOptions = None,
) -> "Page":
"""Browser.newPage

Expand Down Expand Up @@ -5987,11 +5993,13 @@ async def newPage(
proxy : Optional[{"server": str, "bypass": Optional[str], "username": Optional[str], "password": Optional[str]}]
Network proxy settings to use with this context. Note that browser needs to be launched with the global proxy for this 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' } })`.
videosPath : Optional[str]
Enables video recording for all pages to `videosPath` folder. If not specified, videos are not recorded. Make sure to await `page.close` for videos to be saved.
**NOTE** Use `recordVideo` instead, it takes precedence over `videosPath`. Enables video recording for all pages to `videosPath` directory. If not specified, videos are not recorded. Make sure to await `page.close` for videos to be saved.
videoSize : Optional[{"width": int, "height": int}]
Specifies dimensions of the automatically recorded video. Can only be used if `videosPath` is set. If not specified the size will be equal to `viewport`. If `viewport` is not configured explicitly the video size defaults to 1280x720. Actual picture of the page will be scaled down if necessary to fit specified size.
**NOTE** Use `recordVideo` instead, it takes precedence over `videoSize`. Specifies dimensions of the automatically recorded video. Can only be used if `videosPath` is set. If not specified the size will be equal to `viewport`. If `viewport` is not configured explicitly the video size defaults to 1280x720. Actual picture of the page will be scaled down if necessary to fit specified size.
recordHar : Optional[{"omitContent": Optional[bool], "path": str}]
Enables HAR recording for all pages into `har.path` file. If not specified, the HAR is not recorded. Make sure to await `page.close` for the HAR to be saved.
Enables HAR recording for all pages into `recordHar.path` file. If not specified, the HAR is not recorded. Make sure to await `page.close` for the HAR to be saved.
recordVideo : Optional[{"dir": str, "size": Optional[{"width": int, "height": int}]}]
Enables video recording for all pages into `recordVideo.dir` directory. If not specified videos are not recorded. Make sure to await `page.close` for videos to be saved.

Returns
-------
Expand Down Expand Up @@ -6021,6 +6029,7 @@ async def newPage(
videosPath=videosPath,
videoSize=videoSize,
recordHar=recordHar,
recordVideo=recordVideo,
)
)

Expand Down Expand Up @@ -6118,7 +6127,7 @@ async def launch(
proxy : Optional[{"server": str, "bypass": Optional[str], "username": Optional[str], "password": Optional[str]}]
Network proxy settings.
downloadsPath : Union[str, pathlib.Path, NoneType]
If specified, accepted downloads are downloaded into this folder. Otherwise, temporary folder is created and is deleted when browser is closed.
If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is deleted when browser is closed.
slowMo : Optional[int]
Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going on.
chromiumSandbox : Optional[bool]
Expand Down Expand Up @@ -6167,7 +6176,7 @@ async def launchPersistentContext(
proxy: ProxyServer = None,
downloadsPath: typing.Union[str, pathlib.Path] = None,
slowMo: int = None,
viewport: IntSize = None,
viewport: typing.Union[IntSize, Literal[0]] = None,
ignoreHTTPSErrors: bool = None,
javaScriptEnabled: bool = None,
bypassCSP: bool = None,
Expand All @@ -6188,6 +6197,7 @@ async def launchPersistentContext(
videosPath: str = None,
videoSize: IntSize = None,
recordHar: RecordHarOptions = None,
recordVideo: RecordVideoOptions = None,
) -> "BrowserContext":
"""BrowserType.launchPersistentContext

Expand Down Expand Up @@ -6220,10 +6230,10 @@ async def launchPersistentContext(
proxy : Optional[{"server": str, "bypass": Optional[str], "username": Optional[str], "password": Optional[str]}]
Network proxy settings.
downloadsPath : Union[str, pathlib.Path, NoneType]
If specified, accepted downloads are downloaded into this folder. Otherwise, temporary folder is created and is deleted when browser is closed.
If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is deleted when browser is closed.
slowMo : Optional[int]
Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going on. Defaults to 0.
viewport : Optional[{"width": int, "height": int}]
viewport : Union[{"width": int, "height": int}, '0', NoneType]
Sets a consistent viewport for each page. Defaults to an 1280x720 viewport. `null` disables the default viewport.
ignoreHTTPSErrors : Optional[bool]
Whether to ignore HTTPS errors during navigation. Defaults to `false`.
Expand Down Expand Up @@ -6259,11 +6269,13 @@ async def launchPersistentContext(
chromiumSandbox : Optional[bool]
Enable Chromium sandboxing. Defaults to `true`.
videosPath : Optional[str]
Enables video recording for all pages to `videosPath` folder. If not specified, videos are not recorded. Make sure to await `browserContext.close` for videos to be saved.
**NOTE** Use `recordVideo` instead, it takes precedence over `videosPath`. Enables video recording for all pages to `videosPath` directory. If not specified, videos are not recorded. Make sure to await `browserContext.close` for videos to be saved.
videoSize : Optional[{"width": int, "height": int}]
Specifies dimensions of the automatically recorded video. Can only be used if `videosPath` is set. If not specified the size will be equal to `viewport`. If `viewport` is not configured explicitly the video size defaults to 1280x720. Actual picture of the page will be scaled down if necessary to fit specified size.
**NOTE** Use `recordVideo` instead, it takes precedence over `videoSize`. Specifies dimensions of the automatically recorded video. Can only be used if `videosPath` is set. If not specified the size will be equal to `viewport`. If `viewport` is not configured explicitly the video size defaults to 1280x720. Actual picture of the page will be scaled down if necessary to fit specified size.
recordHar : Optional[{"omitContent": Optional[bool], "path": str}]
Enables HAR recording for all the pages into `har.path` file. If not specified, HAR is not recorded. Make sure to await `page.close` for HAR to be saved.
Enables HAR recording for all the pages into `recordHar.path` file. If not specified, HAR is not recorded. Make sure to await `page.close` for HAR to be saved.
recordVideo : Optional[{"dir": str, "size": Optional[{"width": int, "height": int}]}]
Enables video recording for all pages into `recordVideo.dir` directory. If not specified videos are not recorded. Make sure to await `browserContext.close` for videos to be saved.

Returns
-------
Expand Down Expand Up @@ -6307,6 +6319,7 @@ async def launchPersistentContext(
videosPath=videosPath,
videoSize=videoSize,
recordHar=recordHar,
recordVideo=recordVideo,
)
)

Expand Down
8 changes: 8 additions & 0 deletions playwright/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
IntSize,
ProxyServer,
RecordHarOptions,
RecordVideoOptions,
is_safe_close_error,
locals_to_params,
)
Expand Down Expand Up @@ -93,6 +94,7 @@ async def newContext(
videosPath: str = None,
videoSize: IntSize = None,
recordHar: RecordHarOptions = None,
recordVideo: RecordVideoOptions = None,
) -> BrowserContext:
params = locals_to_params(locals())
# Python is strict in which variables gets passed to methods. We get this
Expand All @@ -104,6 +106,11 @@ async def newContext(
params["noDefaultViewport"] = True
if extraHTTPHeaders:
params["extraHTTPHeaders"] = serialize_headers(extraHTTPHeaders)
if not recordVideo and videosPath:
params["recordVideo"] = {"dir": videosPath}
if videoSize:
params["recordVideo"]["size"] = videoSize

channel = await self._channel.send("newContext", params)
context = from_channel(channel)
self._contexts.append(context)
Expand Down Expand Up @@ -135,6 +142,7 @@ async def newPage(
videosPath: str = None,
videoSize: IntSize = None,
recordHar: RecordHarOptions = None,
recordVideo: RecordVideoOptions = None,
) -> Page:
params = locals_to_params(locals())
# Python is strict in which variables gets passed to methods. We get this
Expand Down
17 changes: 16 additions & 1 deletion playwright/browser_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import sys
from pathlib import Path
from typing import Dict, List, Union

Expand All @@ -26,11 +27,17 @@
IntSize,
ProxyServer,
RecordHarOptions,
RecordVideoOptions,
locals_to_params,
not_installed_error,
)
from playwright.network import serialize_headers

if sys.version_info >= (3, 8): # pragma: no cover
from typing import Literal
else: # pragma: no cover
from typing_extensions import Literal


class BrowserType(ChannelOwner):
def __init__(
Expand Down Expand Up @@ -89,7 +96,7 @@ async def launchPersistentContext(
proxy: ProxyServer = None,
downloadsPath: Union[str, Path] = None,
slowMo: int = None,
viewport: IntSize = None,
viewport: Union[IntSize, Literal[0]] = None,
ignoreHTTPSErrors: bool = None,
javaScriptEnabled: bool = None,
bypassCSP: bool = None,
Expand All @@ -110,11 +117,19 @@ async def launchPersistentContext(
videosPath: str = None,
videoSize: IntSize = None,
recordHar: RecordHarOptions = None,
recordVideo: RecordVideoOptions = None,
) -> BrowserContext:
userDataDir = str(Path(userDataDir))
params = locals_to_params(locals())
if viewport == 0:
del params["viewport"]
params["noDefaultViewport"] = True
if extraHTTPHeaders:
params["extraHTTPHeaders"] = serialize_headers(extraHTTPHeaders)
if not recordVideo and videosPath:
params["recordVideo"] = {"dir": videosPath}
if videoSize:
params["recordVideo"]["size"] = videoSize
normalize_launch_params(params)
try:
context = from_channel(
Expand Down
5 changes: 5 additions & 0 deletions playwright/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ class RecordHarOptions(TypedDict):
path: str


class RecordVideoOptions(TypedDict):
dir: str
size: Optional[Viewport]


DeviceDescriptor = TypedDict(
"DeviceDescriptor",
{
Expand Down
7 changes: 7 additions & 0 deletions playwright/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ def _add_event_handler(self, event: str, k: Any, v: Any) -> None:
self._channel.send_no_reply(
"setFileChooserInterceptedNoReply", {"intercepted": True}
)
if event == Page.Events.WebSocket and len(self.listeners(event)) == 0:
self._channel.send_no_reply(
"setWebSocketFramesReportingEnabledNoReply", {"enabled": True}
)
super()._add_event_handler(event, k, v)

def remove_listener(self, event: str, f: Any) -> None:
Expand All @@ -302,6 +306,9 @@ def remove_listener(self, event: str, f: Any) -> None:
self._channel.send_no_reply(
"setFileChooserInterceptedNoReply", {"intercepted": False}
)
# Note: we do not stop reporting web socket frames, since
# user might not listen to 'websocket' anymore, but still have
# a functioning WebSocket object.

@property
def context(self) -> "BrowserContext":
Expand Down
Loading