Skip to content

Commit 8e9c796

Browse files
committed
Placeholder commit for microsoft#1382
1 parent a75e9d0 commit 8e9c796

File tree

10 files changed

+443
-18
lines changed

10 files changed

+443
-18
lines changed

playwright/_impl/_browser.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import json
1717
from pathlib import Path
1818
from types import SimpleNamespace
19-
from typing import TYPE_CHECKING, Any, Dict, List, Union, cast
19+
from typing import TYPE_CHECKING, Any, Dict, List, Pattern, Union, cast
2020

2121
from playwright._impl._api_structures import (
2222
Geolocation,
@@ -31,6 +31,8 @@
3131
from playwright._impl._helper import (
3232
ColorScheme,
3333
ForcedColors,
34+
HarContentPolicy,
35+
HarMode,
3436
ReducedMotion,
3537
ServiceWorkersPolicy,
3638
async_readfile,
@@ -40,6 +42,7 @@
4042
from playwright._impl._local_utils import LocalUtils
4143
from playwright._impl._network import serialize_headers
4244
from playwright._impl._page import Page
45+
from playwright._impl._str_utils import escape_regex_flags
4346

4447
if TYPE_CHECKING: # pragma: no cover
4548
from playwright._impl._browser_type import BrowserType
@@ -116,6 +119,9 @@ async def new_context(
116119
baseURL: str = None,
117120
strictSelectors: bool = None,
118121
serviceWorkers: ServiceWorkersPolicy = None,
122+
recordHarUrlFilter: Union[Pattern, str] = None,
123+
recordHarMode: HarMode = None,
124+
recordHarContent: HarContentPolicy = None,
119125
) -> BrowserContext:
120126
params = locals_to_params(locals())
121127
await normalize_context_params(self._connection._is_sync, params)
@@ -161,6 +167,9 @@ async def new_page(
161167
baseURL: str = None,
162168
strictSelectors: bool = None,
163169
serviceWorkers: ServiceWorkersPolicy = None,
170+
recordHarUrlFilter: Union[Pattern, str] = None,
171+
recordHarMode: HarMode = None,
172+
recordHarContent: HarContentPolicy = None,
164173
) -> Page:
165174
params = locals_to_params(locals())
166175
context = await self.new_context(**params)
@@ -218,9 +227,30 @@ async def normalize_context_params(is_sync: bool, params: Dict) -> None:
218227
if "recordHarPath" in params:
219228
recordHar: Dict[str, Any] = {"path": str(params["recordHarPath"])}
220229
params["recordHar"] = recordHar
230+
if "recordHarUrlFilter" in params:
231+
opt = params["recordHarUrlFilter"]
232+
if isinstance(opt, str):
233+
params["recordHar"]["urlGlob"] = opt
234+
if isinstance(opt, Pattern):
235+
params["recordHar"]["urlRegexSource"] = opt.pattern
236+
params["recordHar"]["urlRegexFlags"] = escape_regex_flags(opt)
237+
del params["recordHarUrlFilter"]
238+
if "recordHarMode" in params:
239+
params["recordHar"]["mode"] = params["recordHarMode"]
240+
del params["recordHarMode"]
241+
242+
new_content_api = None
243+
old_content_api = None
244+
if "recordHarContent" in params:
245+
new_content_api = params["recordHarContent"]
246+
del params["recordHarContent"]
221247
if "recordHarOmitContent" in params:
222-
params["recordHar"]["omitContent"] = params["recordHarOmitContent"]
248+
old_content_api = params["recordHarOmitContent"]
223249
del params["recordHarOmitContent"]
250+
content = new_content_api or ("omit" if old_content_api else None)
251+
if content:
252+
params["recordHar"]["content"] = content
253+
224254
del params["recordHarPath"]
225255
if "recordVideoDir" in params:
226256
params["recordVideo"] = {"dir": str(params["recordVideoDir"])}

playwright/_impl/_browser_type.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import asyncio
1616
import pathlib
1717
from pathlib import Path
18-
from typing import TYPE_CHECKING, Dict, List, Optional, Union, cast
18+
from typing import TYPE_CHECKING, Dict, List, Optional, Pattern, Union, cast
1919

2020
from playwright._impl._api_structures import (
2121
Geolocation,
@@ -36,6 +36,8 @@
3636
ColorScheme,
3737
Env,
3838
ForcedColors,
39+
HarContentPolicy,
40+
HarMode,
3941
ReducedMotion,
4042
ServiceWorkersPolicy,
4143
locals_to_params,
@@ -140,6 +142,9 @@ async def launch_persistent_context(
140142
baseURL: str = None,
141143
strictSelectors: bool = None,
142144
serviceWorkers: ServiceWorkersPolicy = None,
145+
recordHarUrlFilter: Union[Pattern, str] = None,
146+
recordHarMode: HarMode = None,
147+
recordHarContent: HarContentPolicy = None,
143148
) -> BrowserContext:
144149
userDataDir = str(Path(userDataDir))
145150
params = locals_to_params(locals())

playwright/_impl/_helper.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@
6565
KeyboardModifier = Literal["Alt", "Control", "Meta", "Shift"]
6666
MouseButton = Literal["left", "middle", "right"]
6767
ServiceWorkersPolicy = Literal["allow", "block"]
68+
HarMode = Literal["full", "minimal"]
69+
HarContentPolicy = Literal["attach", "embed", "omit"]
6870

6971

7072
class ErrorPayload(TypedDict, total=False):

playwright/async_api/_generated.py

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10730,7 +10730,10 @@ async def new_context(
1073010730
storage_state: typing.Union[StorageState, str, pathlib.Path] = None,
1073110731
base_url: str = None,
1073210732
strict_selectors: bool = None,
10733-
service_workers: Literal["allow", "block"] = None
10733+
service_workers: Literal["allow", "block"] = None,
10734+
record_har_url_filter: typing.Union[str, typing.Pattern] = None,
10735+
record_har_mode: Literal["full", "minimal"] = None,
10736+
record_har_content: Literal["attach", "embed", "omit"] = None
1073410737
) -> "BrowserContext":
1073510738
"""Browser.new_context
1073610739

@@ -10839,6 +10842,14 @@ async def new_context(
1083910842
Whether to allow sites to register Service workers. Defaults to `'allow'`.
1084010843
- `'allow'`: [Service Workers](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API) can be registered.
1084110844
- `'block'`: Playwright will block all registration of Service Workers.
10845+
record_har_url_filter : Union[Pattern, str, NoneType]
10846+
record_har_mode : Union["full", "minimal", NoneType]
10847+
When set to `minimal`, only record information necessary for routing from HAR. This omits sizes, timing, page, cookies,
10848+
security and other types of HAR information that are not used when replaying from HAR. Defaults to `full`.
10849+
record_har_content : Union["attach", "embed", "omit", NoneType]
10850+
Optional setting to control resource content management. If `omit` is specified, content is not persisted. If `attach`
10851+
is specified, resources are persistet as separate files and all of these files are archived along with the HAR file.
10852+
Defaults to `embed`, which stores content inline the HAR file as per HAR specification.
1084210853

1084310854
Returns
1084410855
-------
@@ -10878,6 +10889,9 @@ async def new_context(
1087810889
baseURL=base_url,
1087910890
strictSelectors=strict_selectors,
1088010891
serviceWorkers=service_workers,
10892+
recordHarUrlFilter=record_har_url_filter,
10893+
recordHarMode=record_har_mode,
10894+
recordHarContent=record_har_content,
1088110895
)
1088210896
)
1088310897

@@ -10914,7 +10928,10 @@ async def new_page(
1091410928
storage_state: typing.Union[StorageState, str, pathlib.Path] = None,
1091510929
base_url: str = None,
1091610930
strict_selectors: bool = None,
10917-
service_workers: Literal["allow", "block"] = None
10931+
service_workers: Literal["allow", "block"] = None,
10932+
record_har_url_filter: typing.Union[str, typing.Pattern] = None,
10933+
record_har_mode: Literal["full", "minimal"] = None,
10934+
record_har_content: Literal["attach", "embed", "omit"] = None
1091810935
) -> "Page":
1091910936
"""Browser.new_page
1092010937

@@ -11018,6 +11035,14 @@ async def new_page(
1101811035
Whether to allow sites to register Service workers. Defaults to `'allow'`.
1101911036
- `'allow'`: [Service Workers](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API) can be registered.
1102011037
- `'block'`: Playwright will block all registration of Service Workers.
11038+
record_har_url_filter : Union[Pattern, str, NoneType]
11039+
record_har_mode : Union["full", "minimal", NoneType]
11040+
When set to `minimal`, only record information necessary for routing from HAR. This omits sizes, timing, page, cookies,
11041+
security and other types of HAR information that are not used when replaying from HAR. Defaults to `full`.
11042+
record_har_content : Union["attach", "embed", "omit", NoneType]
11043+
Optional setting to control resource content management. If `omit` is specified, content is not persisted. If `attach`
11044+
is specified, resources are persistet as separate files and all of these files are archived along with the HAR file.
11045+
Defaults to `embed`, which stores content inline the HAR file as per HAR specification.
1102111046

1102211047
Returns
1102311048
-------
@@ -11057,6 +11082,9 @@ async def new_page(
1105711082
baseURL=base_url,
1105811083
strictSelectors=strict_selectors,
1105911084
serviceWorkers=service_workers,
11085+
recordHarUrlFilter=record_har_url_filter,
11086+
recordHarMode=record_har_mode,
11087+
recordHarContent=record_har_content,
1106011088
)
1106111089
)
1106211090

@@ -11352,7 +11380,10 @@ async def launch_persistent_context(
1135211380
record_video_size: ViewportSize = None,
1135311381
base_url: str = None,
1135411382
strict_selectors: bool = None,
11355-
service_workers: Literal["allow", "block"] = None
11383+
service_workers: Literal["allow", "block"] = None,
11384+
record_har_url_filter: typing.Union[str, typing.Pattern] = None,
11385+
record_har_mode: Literal["full", "minimal"] = None,
11386+
record_har_content: Literal["attach", "embed", "omit"] = None
1135611387
) -> "BrowserContext":
1135711388
"""BrowserType.launch_persistent_context
1135811389

@@ -11496,6 +11527,14 @@ async def launch_persistent_context(
1149611527
Whether to allow sites to register Service workers. Defaults to `'allow'`.
1149711528
- `'allow'`: [Service Workers](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API) can be registered.
1149811529
- `'block'`: Playwright will block all registration of Service Workers.
11530+
record_har_url_filter : Union[Pattern, str, NoneType]
11531+
record_har_mode : Union["full", "minimal", NoneType]
11532+
When set to `minimal`, only record information necessary for routing from HAR. This omits sizes, timing, page, cookies,
11533+
security and other types of HAR information that are not used when replaying from HAR. Defaults to `full`.
11534+
record_har_content : Union["attach", "embed", "omit", NoneType]
11535+
Optional setting to control resource content management. If `omit` is specified, content is not persisted. If `attach`
11536+
is specified, resources are persistet as separate files and all of these files are archived along with the HAR file.
11537+
Defaults to `embed`, which stores content inline the HAR file as per HAR specification.
1149911538

1150011539
Returns
1150111540
-------
@@ -11549,6 +11588,9 @@ async def launch_persistent_context(
1154911588
baseURL=base_url,
1155011589
strictSelectors=strict_selectors,
1155111590
serviceWorkers=service_workers,
11591+
recordHarUrlFilter=record_har_url_filter,
11592+
recordHarMode=record_har_mode,
11593+
recordHarContent=record_har_content,
1155211594
)
1155311595
)
1155411596

playwright/sync_api/_generated.py

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10754,7 +10754,10 @@ def new_context(
1075410754
storage_state: typing.Union[StorageState, str, pathlib.Path] = None,
1075510755
base_url: str = None,
1075610756
strict_selectors: bool = None,
10757-
service_workers: Literal["allow", "block"] = None
10757+
service_workers: Literal["allow", "block"] = None,
10758+
record_har_url_filter: typing.Union[str, typing.Pattern] = None,
10759+
record_har_mode: Literal["full", "minimal"] = None,
10760+
record_har_content: Literal["attach", "embed", "omit"] = None
1075810761
) -> "BrowserContext":
1075910762
"""Browser.new_context
1076010763

@@ -10863,6 +10866,14 @@ def new_context(
1086310866
Whether to allow sites to register Service workers. Defaults to `'allow'`.
1086410867
- `'allow'`: [Service Workers](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API) can be registered.
1086510868
- `'block'`: Playwright will block all registration of Service Workers.
10869+
record_har_url_filter : Union[Pattern, str, NoneType]
10870+
record_har_mode : Union["full", "minimal", NoneType]
10871+
When set to `minimal`, only record information necessary for routing from HAR. This omits sizes, timing, page, cookies,
10872+
security and other types of HAR information that are not used when replaying from HAR. Defaults to `full`.
10873+
record_har_content : Union["attach", "embed", "omit", NoneType]
10874+
Optional setting to control resource content management. If `omit` is specified, content is not persisted. If `attach`
10875+
is specified, resources are persistet as separate files and all of these files are archived along with the HAR file.
10876+
Defaults to `embed`, which stores content inline the HAR file as per HAR specification.
1086610877

1086710878
Returns
1086810879
-------
@@ -10903,6 +10914,9 @@ def new_context(
1090310914
baseURL=base_url,
1090410915
strictSelectors=strict_selectors,
1090510916
serviceWorkers=service_workers,
10917+
recordHarUrlFilter=record_har_url_filter,
10918+
recordHarMode=record_har_mode,
10919+
recordHarContent=record_har_content,
1090610920
)
1090710921
)
1090810922
)
@@ -10940,7 +10954,10 @@ def new_page(
1094010954
storage_state: typing.Union[StorageState, str, pathlib.Path] = None,
1094110955
base_url: str = None,
1094210956
strict_selectors: bool = None,
10943-
service_workers: Literal["allow", "block"] = None
10957+
service_workers: Literal["allow", "block"] = None,
10958+
record_har_url_filter: typing.Union[str, typing.Pattern] = None,
10959+
record_har_mode: Literal["full", "minimal"] = None,
10960+
record_har_content: Literal["attach", "embed", "omit"] = None
1094410961
) -> "Page":
1094510962
"""Browser.new_page
1094610963

@@ -11044,6 +11061,14 @@ def new_page(
1104411061
Whether to allow sites to register Service workers. Defaults to `'allow'`.
1104511062
- `'allow'`: [Service Workers](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API) can be registered.
1104611063
- `'block'`: Playwright will block all registration of Service Workers.
11064+
record_har_url_filter : Union[Pattern, str, NoneType]
11065+
record_har_mode : Union["full", "minimal", NoneType]
11066+
When set to `minimal`, only record information necessary for routing from HAR. This omits sizes, timing, page, cookies,
11067+
security and other types of HAR information that are not used when replaying from HAR. Defaults to `full`.
11068+
record_har_content : Union["attach", "embed", "omit", NoneType]
11069+
Optional setting to control resource content management. If `omit` is specified, content is not persisted. If `attach`
11070+
is specified, resources are persistet as separate files and all of these files are archived along with the HAR file.
11071+
Defaults to `embed`, which stores content inline the HAR file as per HAR specification.
1104711072

1104811073
Returns
1104911074
-------
@@ -11084,6 +11109,9 @@ def new_page(
1108411109
baseURL=base_url,
1108511110
strictSelectors=strict_selectors,
1108611111
serviceWorkers=service_workers,
11112+
recordHarUrlFilter=record_har_url_filter,
11113+
recordHarMode=record_har_mode,
11114+
recordHarContent=record_har_content,
1108711115
)
1108811116
)
1108911117
)
@@ -11384,7 +11412,10 @@ def launch_persistent_context(
1138411412
record_video_size: ViewportSize = None,
1138511413
base_url: str = None,
1138611414
strict_selectors: bool = None,
11387-
service_workers: Literal["allow", "block"] = None
11415+
service_workers: Literal["allow", "block"] = None,
11416+
record_har_url_filter: typing.Union[str, typing.Pattern] = None,
11417+
record_har_mode: Literal["full", "minimal"] = None,
11418+
record_har_content: Literal["attach", "embed", "omit"] = None
1138811419
) -> "BrowserContext":
1138911420
"""BrowserType.launch_persistent_context
1139011421

@@ -11528,6 +11559,14 @@ def launch_persistent_context(
1152811559
Whether to allow sites to register Service workers. Defaults to `'allow'`.
1152911560
- `'allow'`: [Service Workers](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API) can be registered.
1153011561
- `'block'`: Playwright will block all registration of Service Workers.
11562+
record_har_url_filter : Union[Pattern, str, NoneType]
11563+
record_har_mode : Union["full", "minimal", NoneType]
11564+
When set to `minimal`, only record information necessary for routing from HAR. This omits sizes, timing, page, cookies,
11565+
security and other types of HAR information that are not used when replaying from HAR. Defaults to `full`.
11566+
record_har_content : Union["attach", "embed", "omit", NoneType]
11567+
Optional setting to control resource content management. If `omit` is specified, content is not persisted. If `attach`
11568+
is specified, resources are persistet as separate files and all of these files are archived along with the HAR file.
11569+
Defaults to `embed`, which stores content inline the HAR file as per HAR specification.
1153111570

1153211571
Returns
1153311572
-------
@@ -11582,6 +11621,9 @@ def launch_persistent_context(
1158211621
baseURL=base_url,
1158311622
strictSelectors=strict_selectors,
1158411623
serviceWorkers=service_workers,
11624+
recordHarUrlFilter=record_har_url_filter,
11625+
recordHarMode=record_har_mode,
11626+
recordHarContent=record_har_content,
1158511627
)
1158611628
)
1158711629
)

scripts/expected_api_mismatch.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,5 @@ Method not implemented: Error.message
2020
Method not implemented: PlaywrightAssertions.expect
2121

2222
# Pending 1.23 ports
23-
Parameter not implemented: BrowserType.launch_persistent_context(record_har_url_filter=)
2423
Method not implemented: BrowserContext.route_from_har
25-
Parameter not implemented: Browser.new_page(record_har_url_filter=)
2624
Method not implemented: Page.route_from_har
27-
Parameter not implemented: Browser.new_context(record_har_url_filter=)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
InWheel = None
3131
from wheel.bdist_wheel import bdist_wheel as BDistWheelCommand
3232

33-
driver_version = "1.23.0-beta-1656026605000"
33+
driver_version = "1.23.0-beta-1656093125000"
3434

3535

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

0 commit comments

Comments
 (0)