|
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | 14 |
|
15 | | -import json |
16 | 15 | from pathlib import Path |
17 | 16 | from types import SimpleNamespace |
18 | 17 | from typing import TYPE_CHECKING, Dict, List, Optional, Pattern, Sequence, Union, cast |
|
38 | 37 | HarMode, |
39 | 38 | ReducedMotion, |
40 | 39 | ServiceWorkersPolicy, |
41 | | - async_readfile, |
42 | 40 | locals_to_params, |
43 | 41 | make_dirs_for_file, |
44 | | - prepare_record_har_options, |
45 | 42 | ) |
46 | | -from playwright._impl._network import serialize_headers, to_client_certificates_protocol |
47 | 43 | from playwright._impl._page import Page |
48 | 44 |
|
49 | 45 | if TYPE_CHECKING: # pragma: no cover |
@@ -157,7 +153,7 @@ async def new_context( |
157 | 153 | clientCertificates: List[ClientCertificate] = None, |
158 | 154 | ) -> BrowserContext: |
159 | 155 | params = locals_to_params(locals()) |
160 | | - await prepare_browser_context_params(params) |
| 156 | + await self._browser_type._prepare_browser_context_params(params) |
161 | 157 |
|
162 | 158 | channel = await self._channel.send("newContext", params) |
163 | 159 | context = cast(BrowserContext, from_channel(channel)) |
@@ -266,43 +262,3 @@ async def stop_tracing(self) -> bytes: |
266 | 262 | f.write(buffer) |
267 | 263 | self._cr_tracing_path = None |
268 | 264 | 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 | | - ) |
0 commit comments