Skip to content

Commit bbdbfe3

Browse files
committed
Fix selector registration
1 parent 39da953 commit bbdbfe3

File tree

2 files changed

+3
-51
lines changed

2 files changed

+3
-51
lines changed

playwright/_impl/_browser.py

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

15-
import json
1615
from pathlib import Path
1716
from types import SimpleNamespace
1817
from typing import TYPE_CHECKING, Dict, List, Optional, Pattern, Sequence, Union, cast
@@ -38,12 +37,9 @@
3837
HarMode,
3938
ReducedMotion,
4039
ServiceWorkersPolicy,
41-
async_readfile,
4240
locals_to_params,
4341
make_dirs_for_file,
44-
prepare_record_har_options,
4542
)
46-
from playwright._impl._network import serialize_headers, to_client_certificates_protocol
4743
from playwright._impl._page import Page
4844

4945
if TYPE_CHECKING: # pragma: no cover
@@ -157,7 +153,7 @@ async def new_context(
157153
clientCertificates: List[ClientCertificate] = None,
158154
) -> BrowserContext:
159155
params = locals_to_params(locals())
160-
await prepare_browser_context_params(params)
156+
await self._browser_type._prepare_browser_context_params(params)
161157

162158
channel = await self._channel.send("newContext", params)
163159
context = cast(BrowserContext, from_channel(channel))
@@ -266,43 +262,3 @@ async def stop_tracing(self) -> bytes:
266262
f.write(buffer)
267263
self._cr_tracing_path = None
268264
return buffer
269-
270-
271-
async def prepare_browser_context_params(params: Dict) -> None:
272-
if params.get("noViewport"):
273-
del params["noViewport"]
274-
params["noDefaultViewport"] = True
275-
if "defaultBrowserType" in params:
276-
del params["defaultBrowserType"]
277-
if "extraHTTPHeaders" in params:
278-
params["extraHTTPHeaders"] = serialize_headers(params["extraHTTPHeaders"])
279-
if "recordHarPath" in params:
280-
params["recordHar"] = prepare_record_har_options(params)
281-
del params["recordHarPath"]
282-
if "recordVideoDir" in params:
283-
params["recordVideo"] = {"dir": Path(params["recordVideoDir"]).absolute()}
284-
if "recordVideoSize" in params:
285-
params["recordVideo"]["size"] = params["recordVideoSize"]
286-
del params["recordVideoSize"]
287-
del params["recordVideoDir"]
288-
if "storageState" in params:
289-
storageState = params["storageState"]
290-
if not isinstance(storageState, dict):
291-
params["storageState"] = json.loads(
292-
(await async_readfile(storageState)).decode()
293-
)
294-
if params.get("colorScheme", None) == "null":
295-
params["colorScheme"] = "no-override"
296-
if params.get("reducedMotion", None) == "null":
297-
params["reducedMotion"] = "no-override"
298-
if params.get("forcedColors", None) == "null":
299-
params["forcedColors"] = "no-override"
300-
if params.get("contrast", None) == "null":
301-
params["contrast"] = "no-override"
302-
if "acceptDownloads" in params:
303-
params["acceptDownloads"] = "accept" if params["acceptDownloads"] else "deny"
304-
305-
if "clientCertificates" in params:
306-
params["clientCertificates"] = await to_client_certificates_protocol(
307-
params["clientCertificates"]
308-
)

playwright/_impl/_browser_type.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,12 +335,8 @@ async def _prepare_browser_context_params(self, params: Dict) -> None:
335335
params["clientCertificates"] = await to_client_certificates_protocol(
336336
params["clientCertificates"]
337337
)
338-
if "selectorEngines" in params:
339-
params["selectorEngines"] = self._playwright.selectors._selectorEngines
340-
if "testIdAttributeName" in params:
341-
params["testIdAttributeName"] = (
342-
self._playwright.selectors._testIdAttributeName
343-
)
338+
params["selectorEngines"] = self._playwright.selectors._selectorEngines
339+
params["testIdAttributeName"] = self._playwright.selectors._testIdAttributeName
344340

345341

346342
def normalize_launch_params(params: Dict) -> None:

0 commit comments

Comments
 (0)