Repository: microsoft/playwright-python

Issue:
[BUG] newPage() got an unexpected keyword argument 'defaultBrowserType'
Repro steps for repl

```
>>> from playwright import sync_playwright
>>> playwright = sync_playwright().start()
>>> browser = playwright.webkit.launch(headless=False)
>>> iPhone11 = playwright.devices['iPhone 11']
>>> context = browser.newContext(**iPhone11)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: newContext() got an unexpected keyword argument 'defaultBrowserType'
```

[Relevant source](https://github.com/microsoft/playwright-python/blob/26ac810f44e88dbade3364f850a06b7b97340a7f/playwright/browser.py#L67).


Discussion:

Resolving patch:
diff --git a/playwright/async_api.py b/playwright/async_api.py
--- a/playwright/async_api.py
+++ b/playwright/async_api.py
@@ -5364,6 +5364,7 @@ async def newContext(
         hasTouch: bool = None,
         colorScheme: Literal["light", "dark", "no-preference"] = None,
         acceptDownloads: bool = None,
+        defaultBrowserType: str = None,
     ) -> "BrowserContext":
         """Browser.newContext
 
@@ -5428,6 +5429,7 @@ async def newContext(
                 hasTouch=hasTouch,
                 colorScheme=colorScheme,
                 acceptDownloads=acceptDownloads,
+                defaultBrowserType=defaultBrowserType,
             )
         )
 
diff --git a/playwright/browser.py b/playwright/browser.py
--- a/playwright/browser.py
+++ b/playwright/browser.py
@@ -83,8 +83,13 @@ async def newContext(
         hasTouch: bool = None,
         colorScheme: ColorScheme = None,
         acceptDownloads: bool = None,
+        defaultBrowserType: str = None,
     ) -> BrowserContext:
         params = locals_to_params(locals())
+        # Python is strict in which variables gets passed to methods. We get this
+        # value from the device descriptors, thats why we have to strip it out.
+        if "defaultBrowserType" in params:
+            del params["defaultBrowserType"]
         if viewport == 0:
             del params["viewport"]
             params["noDefaultViewport"] = True
diff --git a/playwright/sync_api.py b/playwright/sync_api.py
--- a/playwright/sync_api.py
+++ b/playwright/sync_api.py
@@ -5592,6 +5592,7 @@ def newContext(
         hasTouch: bool = None,
         colorScheme: Literal["light", "dark", "no-preference"] = None,
         acceptDownloads: bool = None,
+        defaultBrowserType: str = None,
     ) -> "BrowserContext":
         """Browser.newContext
 
@@ -5657,6 +5658,7 @@ def newContext(
                     hasTouch=hasTouch,
                     colorScheme=colorScheme,
                     acceptDownloads=acceptDownloads,
+                    defaultBrowserType=defaultBrowserType,
                 )
             )
         )


Test patch:
diff --git a/tests/async/test_issues.py b/tests/async/test_issues.py
--- a/tests/async/test_issues.py
+++ b/tests/async/test_issues.py
@@ -7,3 +7,10 @@ async def test_issue_189(browser_type):
     page = await browser.newPage()
     assert await page.evaluate("1 + 1") == 2
     await browser.close()
+
+
+@pytest.mark.only_browser("chromium")
+async def test_issue_195(playwright, browser):
+    iphone_11 = playwright.devices["iPhone 11"]
+    context = await browser.newContext(**iphone_11)
+    await context.close()