From 888f143fb785780f7dd0c8f1d50a0d3df3c6fbb6 Mon Sep 17 00:00:00 2001 From: Pavel Date: Fri, 30 Oct 2020 13:58:01 -0700 Subject: [PATCH] feat(proxy): enable per-context http proxy --- playwright/async_api.py | 8 ++++++++ playwright/browser.py | 3 +++ playwright/sync_api.py | 8 ++++++++ scripts/expected_api_mismatch.txt | 5 ----- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/playwright/async_api.py b/playwright/async_api.py index 02b3c2f25..270bb586f 100644 --- a/playwright/async_api.py +++ b/playwright/async_api.py @@ -5840,6 +5840,7 @@ async def newContext( colorScheme: Literal["dark", "light", "no-preference"] = None, acceptDownloads: bool = None, defaultBrowserType: str = None, + proxy: ProxyServer = None, videosPath: str = None, videoSize: IntSize = None, recordHar: RecordHarOptions = None, @@ -5883,6 +5884,8 @@ async def newContext( Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See page.emulateMedia(options) for more details. Defaults to '`light`'. acceptDownloads : Optional[bool] Whether to automatically download all the attachments. Defaults to `false` where all the downloads are canceled. + proxy : Optional[{"server": str, "bypass": Optional[str], "username": Optional[str], "password": Optional[str]}] + Network proxy settings to use with this context. Note that browser needs to be launched with the global proxy for this option to work. If all contexts override the proxy, global proxy will be never used and can be any string, for example `launch({ proxy: { server: 'per-proxy' } })`. videosPath : Optional[str] Enables video recording for all pages to `videosPath` folder. If not specified, videos are not recorded. Make sure to await `browserContext.close` for videos to be saved. videoSize : Optional[{"width": int, "height": int}] @@ -5914,6 +5917,7 @@ async def newContext( colorScheme=colorScheme, acceptDownloads=acceptDownloads, defaultBrowserType=defaultBrowserType, + proxy=proxy, videosPath=videosPath, videoSize=videoSize, recordHar=recordHar, @@ -5940,6 +5944,7 @@ async def newPage( colorScheme: Literal["dark", "light", "no-preference"] = None, acceptDownloads: bool = None, defaultBrowserType: str = None, + proxy: ProxyServer = None, videosPath: str = None, videoSize: IntSize = None, recordHar: RecordHarOptions = None, @@ -5984,6 +5989,8 @@ async def newPage( Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See page.emulateMedia(options) for more details. Defaults to '`light`'. acceptDownloads : Optional[bool] Whether to automatically download all the attachments. Defaults to `false` where all the downloads are canceled. + proxy : Optional[{"server": str, "bypass": Optional[str], "username": Optional[str], "password": Optional[str]}] + Network proxy settings to use with this context. Note that browser needs to be launched with the global proxy for this option to work. If all contexts override the proxy, global proxy will be never used and can be any string, for example `launch({ proxy: { server: 'per-proxy' } })`. videosPath : Optional[str] Enables video recording for all pages to `videosPath` folder. If not specified, videos are not recorded. Make sure to await `page.close` for videos to be saved. videoSize : Optional[{"width": int, "height": int}] @@ -6015,6 +6022,7 @@ async def newPage( colorScheme=colorScheme, acceptDownloads=acceptDownloads, defaultBrowserType=defaultBrowserType, + proxy=proxy, videosPath=videosPath, videoSize=videoSize, recordHar=recordHar, diff --git a/playwright/browser.py b/playwright/browser.py index bfd1cc474..58e10c8b0 100644 --- a/playwright/browser.py +++ b/playwright/browser.py @@ -23,6 +23,7 @@ Credentials, Geolocation, IntSize, + ProxyServer, RecordHarOptions, locals_to_params, ) @@ -87,6 +88,7 @@ async def newContext( colorScheme: ColorScheme = None, acceptDownloads: bool = None, defaultBrowserType: str = None, + proxy: ProxyServer = None, videosPath: str = None, videoSize: IntSize = None, recordHar: RecordHarOptions = None, @@ -128,6 +130,7 @@ async def newPage( colorScheme: ColorScheme = None, acceptDownloads: bool = None, defaultBrowserType: str = None, + proxy: ProxyServer = None, videosPath: str = None, videoSize: IntSize = None, recordHar: RecordHarOptions = None, diff --git a/playwright/sync_api.py b/playwright/sync_api.py index e608d4e31..632d30789 100644 --- a/playwright/sync_api.py +++ b/playwright/sync_api.py @@ -6076,6 +6076,7 @@ def newContext( colorScheme: Literal["dark", "light", "no-preference"] = None, acceptDownloads: bool = None, defaultBrowserType: str = None, + proxy: ProxyServer = None, videosPath: str = None, videoSize: IntSize = None, recordHar: RecordHarOptions = None, @@ -6119,6 +6120,8 @@ def newContext( Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See page.emulateMedia(options) for more details. Defaults to '`light`'. acceptDownloads : Optional[bool] Whether to automatically download all the attachments. Defaults to `false` where all the downloads are canceled. + proxy : Optional[{"server": str, "bypass": Optional[str], "username": Optional[str], "password": Optional[str]}] + Network proxy settings to use with this context. Note that browser needs to be launched with the global proxy for this option to work. If all contexts override the proxy, global proxy will be never used and can be any string, for example `launch({ proxy: { server: 'per-proxy' } })`. videosPath : Optional[str] Enables video recording for all pages to `videosPath` folder. If not specified, videos are not recorded. Make sure to await `browserContext.close` for videos to be saved. videoSize : Optional[{"width": int, "height": int}] @@ -6151,6 +6154,7 @@ def newContext( colorScheme=colorScheme, acceptDownloads=acceptDownloads, defaultBrowserType=defaultBrowserType, + proxy=proxy, videosPath=videosPath, videoSize=videoSize, recordHar=recordHar, @@ -6178,6 +6182,7 @@ def newPage( colorScheme: Literal["dark", "light", "no-preference"] = None, acceptDownloads: bool = None, defaultBrowserType: str = None, + proxy: ProxyServer = None, videosPath: str = None, videoSize: IntSize = None, recordHar: RecordHarOptions = None, @@ -6222,6 +6227,8 @@ def newPage( Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See page.emulateMedia(options) for more details. Defaults to '`light`'. acceptDownloads : Optional[bool] Whether to automatically download all the attachments. Defaults to `false` where all the downloads are canceled. + proxy : Optional[{"server": str, "bypass": Optional[str], "username": Optional[str], "password": Optional[str]}] + Network proxy settings to use with this context. Note that browser needs to be launched with the global proxy for this option to work. If all contexts override the proxy, global proxy will be never used and can be any string, for example `launch({ proxy: { server: 'per-proxy' } })`. videosPath : Optional[str] Enables video recording for all pages to `videosPath` folder. If not specified, videos are not recorded. Make sure to await `page.close` for videos to be saved. videoSize : Optional[{"width": int, "height": int}] @@ -6254,6 +6261,7 @@ def newPage( colorScheme=colorScheme, acceptDownloads=acceptDownloads, defaultBrowserType=defaultBrowserType, + proxy=proxy, videosPath=videosPath, videoSize=videoSize, recordHar=recordHar, diff --git a/scripts/expected_api_mismatch.txt b/scripts/expected_api_mismatch.txt index 64cdd43e6..8e49efe7f 100644 --- a/scripts/expected_api_mismatch.txt +++ b/scripts/expected_api_mismatch.txt @@ -116,8 +116,3 @@ Parameter not implemented: BrowserContext.addInitScript(arg=) # OptionsOr Parameter not implemented: Page.waitForEvent(optionsOrPredicate=) Parameter not implemented: BrowserContext.waitForEvent(optionsOrPredicate=) - - -# 1.6 Todo -Parameter not implemented: Browser.newPage(proxy=) -Parameter not implemented: Browser.newContext(proxy=)