Skip to content

Commit 87c5e1b

Browse files
authored
chore: roll Playwright to 1.6 (microsoft#294)
1 parent fe413f0 commit 87c5e1b

10 files changed

+96
-33
lines changed

build_package.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
from playwright.path_utils import get_file_dirname
2424

25-
driver_version_64 = "0.160.0-next.1604373941495"
26-
driver_version_32 = "0.160.0-next.1604373978475"
25+
driver_version_64 = "0.160.0-next.1605227932803"
26+
driver_version_32 = "0.160.0-next.1605227936643"
2727

2828

2929
def driver_version(platform: str) -> str:

buildbots/test-sync-generation.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ function assert_script {
55
oldfile="playwright/$2"
66
echo "Testing $newfile against $oldfile"
77

8-
python $1 > $newfile
8+
if ! python $1 > $newfile; then
9+
exit 1
10+
fi
911

1012
pre-commit run --files $newfile
1113

1214
cmp $oldfile $newfile
1315
exit_code=$?
1416
rm $newfile
15-
return $exit_code
1617
}
1718

1819
assert_script "scripts/generate_sync_api.py" "sync_api.py"

playwright/async_api.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
PdfMargins,
5151
ProxyServer,
5252
RecordHarOptions,
53+
RecordVideoOptions,
5354
RequestFailure,
5455
ResourceTiming,
5556
SelectOption,
@@ -5839,6 +5840,7 @@ async def newContext(
58395840
videosPath: str = None,
58405841
videoSize: IntSize = None,
58415842
recordHar: RecordHarOptions = None,
5843+
recordVideo: RecordVideoOptions = None,
58425844
) -> "BrowserContext":
58435845
"""Browser.newContext
58445846
@@ -5882,11 +5884,13 @@ async def newContext(
58825884
proxy : Optional[{"server": str, "bypass": Optional[str], "username": Optional[str], "password": Optional[str]}]
58835885
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' } })`.
58845886
videosPath : Optional[str]
5885-
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.
5887+
**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.
58865888
videoSize : Optional[{"width": int, "height": int}]
5887-
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.
5889+
**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.
58885890
recordHar : Optional[{"omitContent": Optional[bool], "path": str}]
5889-
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.
5891+
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.
5892+
recordVideo : Optional[{"dir": str, "size": Optional[{"width": int, "height": int}]}]
5893+
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.
58905894
58915895
Returns
58925896
-------
@@ -5916,6 +5920,7 @@ async def newContext(
59165920
videosPath=videosPath,
59175921
videoSize=videoSize,
59185922
recordHar=recordHar,
5923+
recordVideo=recordVideo,
59195924
)
59205925
)
59215926

@@ -5943,6 +5948,7 @@ async def newPage(
59435948
videosPath: str = None,
59445949
videoSize: IntSize = None,
59455950
recordHar: RecordHarOptions = None,
5951+
recordVideo: RecordVideoOptions = None,
59465952
) -> "Page":
59475953
"""Browser.newPage
59485954
@@ -5987,11 +5993,13 @@ async def newPage(
59875993
proxy : Optional[{"server": str, "bypass": Optional[str], "username": Optional[str], "password": Optional[str]}]
59885994
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' } })`.
59895995
videosPath : Optional[str]
5990-
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.
5996+
**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.
59915997
videoSize : Optional[{"width": int, "height": int}]
5992-
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.
5998+
**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.
59935999
recordHar : Optional[{"omitContent": Optional[bool], "path": str}]
5994-
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.
6000+
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.
6001+
recordVideo : Optional[{"dir": str, "size": Optional[{"width": int, "height": int}]}]
6002+
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.
59956003
59966004
Returns
59976005
-------
@@ -6021,6 +6029,7 @@ async def newPage(
60216029
videosPath=videosPath,
60226030
videoSize=videoSize,
60236031
recordHar=recordHar,
6032+
recordVideo=recordVideo,
60246033
)
60256034
)
60266035

@@ -6118,7 +6127,7 @@ async def launch(
61186127
proxy : Optional[{"server": str, "bypass": Optional[str], "username": Optional[str], "password": Optional[str]}]
61196128
Network proxy settings.
61206129
downloadsPath : Union[str, pathlib.Path, NoneType]
6121-
If specified, accepted downloads are downloaded into this folder. Otherwise, temporary folder is created and is deleted when browser is closed.
6130+
If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is deleted when browser is closed.
61226131
slowMo : Optional[int]
61236132
Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going on.
61246133
chromiumSandbox : Optional[bool]
@@ -6167,7 +6176,7 @@ async def launchPersistentContext(
61676176
proxy: ProxyServer = None,
61686177
downloadsPath: typing.Union[str, pathlib.Path] = None,
61696178
slowMo: int = None,
6170-
viewport: IntSize = None,
6179+
viewport: typing.Union[IntSize, Literal[0]] = None,
61716180
ignoreHTTPSErrors: bool = None,
61726181
javaScriptEnabled: bool = None,
61736182
bypassCSP: bool = None,
@@ -6188,6 +6197,7 @@ async def launchPersistentContext(
61886197
videosPath: str = None,
61896198
videoSize: IntSize = None,
61906199
recordHar: RecordHarOptions = None,
6200+
recordVideo: RecordVideoOptions = None,
61916201
) -> "BrowserContext":
61926202
"""BrowserType.launchPersistentContext
61936203
@@ -6220,10 +6230,10 @@ async def launchPersistentContext(
62206230
proxy : Optional[{"server": str, "bypass": Optional[str], "username": Optional[str], "password": Optional[str]}]
62216231
Network proxy settings.
62226232
downloadsPath : Union[str, pathlib.Path, NoneType]
6223-
If specified, accepted downloads are downloaded into this folder. Otherwise, temporary folder is created and is deleted when browser is closed.
6233+
If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is deleted when browser is closed.
62246234
slowMo : Optional[int]
62256235
Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going on. Defaults to 0.
6226-
viewport : Optional[{"width": int, "height": int}]
6236+
viewport : Union[{"width": int, "height": int}, '0', NoneType]
62276237
Sets a consistent viewport for each page. Defaults to an 1280x720 viewport. `null` disables the default viewport.
62286238
ignoreHTTPSErrors : Optional[bool]
62296239
Whether to ignore HTTPS errors during navigation. Defaults to `false`.
@@ -6259,11 +6269,13 @@ async def launchPersistentContext(
62596269
chromiumSandbox : Optional[bool]
62606270
Enable Chromium sandboxing. Defaults to `true`.
62616271
videosPath : Optional[str]
6262-
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.
6272+
**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.
62636273
videoSize : Optional[{"width": int, "height": int}]
6264-
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.
6274+
**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.
62656275
recordHar : Optional[{"omitContent": Optional[bool], "path": str}]
6266-
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.
6276+
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.
6277+
recordVideo : Optional[{"dir": str, "size": Optional[{"width": int, "height": int}]}]
6278+
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.
62676279
62686280
Returns
62696281
-------
@@ -6307,6 +6319,7 @@ async def launchPersistentContext(
63076319
videosPath=videosPath,
63086320
videoSize=videoSize,
63096321
recordHar=recordHar,
6322+
recordVideo=recordVideo,
63106323
)
63116324
)
63126325

playwright/browser.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
IntSize,
2626
ProxyServer,
2727
RecordHarOptions,
28+
RecordVideoOptions,
2829
is_safe_close_error,
2930
locals_to_params,
3031
)
@@ -93,6 +94,7 @@ async def newContext(
9394
videosPath: str = None,
9495
videoSize: IntSize = None,
9596
recordHar: RecordHarOptions = None,
97+
recordVideo: RecordVideoOptions = None,
9698
) -> BrowserContext:
9799
params = locals_to_params(locals())
98100
# Python is strict in which variables gets passed to methods. We get this
@@ -104,6 +106,11 @@ async def newContext(
104106
params["noDefaultViewport"] = True
105107
if extraHTTPHeaders:
106108
params["extraHTTPHeaders"] = serialize_headers(extraHTTPHeaders)
109+
if not recordVideo and videosPath:
110+
params["recordVideo"] = {"dir": videosPath}
111+
if videoSize:
112+
params["recordVideo"]["size"] = videoSize
113+
107114
channel = await self._channel.send("newContext", params)
108115
context = from_channel(channel)
109116
self._contexts.append(context)
@@ -135,6 +142,7 @@ async def newPage(
135142
videosPath: str = None,
136143
videoSize: IntSize = None,
137144
recordHar: RecordHarOptions = None,
145+
recordVideo: RecordVideoOptions = None,
138146
) -> Page:
139147
params = locals_to_params(locals())
140148
# Python is strict in which variables gets passed to methods. We get this

playwright/browser_type.py

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

15+
import sys
1516
from pathlib import Path
1617
from typing import Dict, List, Union
1718

@@ -26,11 +27,17 @@
2627
IntSize,
2728
ProxyServer,
2829
RecordHarOptions,
30+
RecordVideoOptions,
2931
locals_to_params,
3032
not_installed_error,
3133
)
3234
from playwright.network import serialize_headers
3335

36+
if sys.version_info >= (3, 8): # pragma: no cover
37+
from typing import Literal
38+
else: # pragma: no cover
39+
from typing_extensions import Literal
40+
3441

3542
class BrowserType(ChannelOwner):
3643
def __init__(
@@ -89,7 +96,7 @@ async def launchPersistentContext(
8996
proxy: ProxyServer = None,
9097
downloadsPath: Union[str, Path] = None,
9198
slowMo: int = None,
92-
viewport: IntSize = None,
99+
viewport: Union[IntSize, Literal[0]] = None,
93100
ignoreHTTPSErrors: bool = None,
94101
javaScriptEnabled: bool = None,
95102
bypassCSP: bool = None,
@@ -110,11 +117,19 @@ async def launchPersistentContext(
110117
videosPath: str = None,
111118
videoSize: IntSize = None,
112119
recordHar: RecordHarOptions = None,
120+
recordVideo: RecordVideoOptions = None,
113121
) -> BrowserContext:
114122
userDataDir = str(Path(userDataDir))
115123
params = locals_to_params(locals())
124+
if viewport == 0:
125+
del params["viewport"]
126+
params["noDefaultViewport"] = True
116127
if extraHTTPHeaders:
117128
params["extraHTTPHeaders"] = serialize_headers(extraHTTPHeaders)
129+
if not recordVideo and videosPath:
130+
params["recordVideo"] = {"dir": videosPath}
131+
if videoSize:
132+
params["recordVideo"]["size"] = videoSize
118133
normalize_launch_params(params)
119134
try:
120135
context = from_channel(

playwright/helper.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ class RecordHarOptions(TypedDict):
190190
path: str
191191

192192

193+
class RecordVideoOptions(TypedDict):
194+
dir: str
195+
size: Optional[Viewport]
196+
197+
193198
DeviceDescriptor = TypedDict(
194199
"DeviceDescriptor",
195200
{

playwright/page.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,10 @@ def _add_event_handler(self, event: str, k: Any, v: Any) -> None:
294294
self._channel.send_no_reply(
295295
"setFileChooserInterceptedNoReply", {"intercepted": True}
296296
)
297+
if event == Page.Events.WebSocket and len(self.listeners(event)) == 0:
298+
self._channel.send_no_reply(
299+
"setWebSocketFramesReportingEnabledNoReply", {"enabled": True}
300+
)
297301
super()._add_event_handler(event, k, v)
298302

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

306313
@property
307314
def context(self) -> "BrowserContext":

0 commit comments

Comments
 (0)