Skip to content

Commit 63d302c

Browse files
authored
fix(context): allow defaultBrowserType keyword (#196)
1 parent 542c3a7 commit 63d302c

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

playwright/async_api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5364,6 +5364,7 @@ async def newContext(
53645364
hasTouch: bool = None,
53655365
colorScheme: Literal["light", "dark", "no-preference"] = None,
53665366
acceptDownloads: bool = None,
5367+
defaultBrowserType: str = None,
53675368
) -> "BrowserContext":
53685369
"""Browser.newContext
53695370
@@ -5428,6 +5429,7 @@ async def newContext(
54285429
hasTouch=hasTouch,
54295430
colorScheme=colorScheme,
54305431
acceptDownloads=acceptDownloads,
5432+
defaultBrowserType=defaultBrowserType,
54315433
)
54325434
)
54335435

playwright/browser.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,13 @@ async def newContext(
8383
hasTouch: bool = None,
8484
colorScheme: ColorScheme = None,
8585
acceptDownloads: bool = None,
86+
defaultBrowserType: str = None,
8687
) -> BrowserContext:
8788
params = locals_to_params(locals())
89+
# Python is strict in which variables gets passed to methods. We get this
90+
# value from the device descriptors, thats why we have to strip it out.
91+
if "defaultBrowserType" in params:
92+
del params["defaultBrowserType"]
8893
if viewport == 0:
8994
del params["viewport"]
9095
params["noDefaultViewport"] = True

playwright/sync_api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5592,6 +5592,7 @@ def newContext(
55925592
hasTouch: bool = None,
55935593
colorScheme: Literal["light", "dark", "no-preference"] = None,
55945594
acceptDownloads: bool = None,
5595+
defaultBrowserType: str = None,
55955596
) -> "BrowserContext":
55965597
"""Browser.newContext
55975598
@@ -5657,6 +5658,7 @@ def newContext(
56575658
hasTouch=hasTouch,
56585659
colorScheme=colorScheme,
56595660
acceptDownloads=acceptDownloads,
5661+
defaultBrowserType=defaultBrowserType,
56605662
)
56615663
)
56625664
)

tests/async/test_issues.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,10 @@ async def test_issue_189(browser_type):
77
page = await browser.newPage()
88
assert await page.evaluate("1 + 1") == 2
99
await browser.close()
10+
11+
12+
@pytest.mark.only_browser("chromium")
13+
async def test_issue_195(playwright, browser):
14+
iphone_11 = playwright.devices["iPhone 11"]
15+
context = await browser.newContext(**iphone_11)
16+
await context.close()

0 commit comments

Comments
 (0)