Skip to content

Commit 7bace3d

Browse files
authored
feat(proxy): enable per-context http proxy (microsoft#266)
1 parent 396fc64 commit 7bace3d

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

playwright/async_api.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5840,6 +5840,7 @@ async def newContext(
58405840
colorScheme: Literal["dark", "light", "no-preference"] = None,
58415841
acceptDownloads: bool = None,
58425842
defaultBrowserType: str = None,
5843+
proxy: ProxyServer = None,
58435844
videosPath: str = None,
58445845
videoSize: IntSize = None,
58455846
recordHar: RecordHarOptions = None,
@@ -5883,6 +5884,8 @@ async def newContext(
58835884
Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See page.emulateMedia(options) for more details. Defaults to '`light`'.
58845885
acceptDownloads : Optional[bool]
58855886
Whether to automatically download all the attachments. Defaults to `false` where all the downloads are canceled.
5887+
proxy : Optional[{"server": str, "bypass": Optional[str], "username": Optional[str], "password": Optional[str]}]
5888+
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' } })`.
58865889
videosPath : Optional[str]
58875890
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.
58885891
videoSize : Optional[{"width": int, "height": int}]
@@ -5914,6 +5917,7 @@ async def newContext(
59145917
colorScheme=colorScheme,
59155918
acceptDownloads=acceptDownloads,
59165919
defaultBrowserType=defaultBrowserType,
5920+
proxy=proxy,
59175921
videosPath=videosPath,
59185922
videoSize=videoSize,
59195923
recordHar=recordHar,
@@ -5940,6 +5944,7 @@ async def newPage(
59405944
colorScheme: Literal["dark", "light", "no-preference"] = None,
59415945
acceptDownloads: bool = None,
59425946
defaultBrowserType: str = None,
5947+
proxy: ProxyServer = None,
59435948
videosPath: str = None,
59445949
videoSize: IntSize = None,
59455950
recordHar: RecordHarOptions = None,
@@ -5984,6 +5989,8 @@ async def newPage(
59845989
Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See page.emulateMedia(options) for more details. Defaults to '`light`'.
59855990
acceptDownloads : Optional[bool]
59865991
Whether to automatically download all the attachments. Defaults to `false` where all the downloads are canceled.
5992+
proxy : Optional[{"server": str, "bypass": Optional[str], "username": Optional[str], "password": Optional[str]}]
5993+
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' } })`.
59875994
videosPath : Optional[str]
59885995
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.
59895996
videoSize : Optional[{"width": int, "height": int}]
@@ -6015,6 +6022,7 @@ async def newPage(
60156022
colorScheme=colorScheme,
60166023
acceptDownloads=acceptDownloads,
60176024
defaultBrowserType=defaultBrowserType,
6025+
proxy=proxy,
60186026
videosPath=videosPath,
60196027
videoSize=videoSize,
60206028
recordHar=recordHar,

playwright/browser.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
Credentials,
2424
Geolocation,
2525
IntSize,
26+
ProxyServer,
2627
RecordHarOptions,
2728
locals_to_params,
2829
)
@@ -87,6 +88,7 @@ async def newContext(
8788
colorScheme: ColorScheme = None,
8889
acceptDownloads: bool = None,
8990
defaultBrowserType: str = None,
91+
proxy: ProxyServer = None,
9092
videosPath: str = None,
9193
videoSize: IntSize = None,
9294
recordHar: RecordHarOptions = None,
@@ -128,6 +130,7 @@ async def newPage(
128130
colorScheme: ColorScheme = None,
129131
acceptDownloads: bool = None,
130132
defaultBrowserType: str = None,
133+
proxy: ProxyServer = None,
131134
videosPath: str = None,
132135
videoSize: IntSize = None,
133136
recordHar: RecordHarOptions = None,

playwright/sync_api.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6076,6 +6076,7 @@ def newContext(
60766076
colorScheme: Literal["dark", "light", "no-preference"] = None,
60776077
acceptDownloads: bool = None,
60786078
defaultBrowserType: str = None,
6079+
proxy: ProxyServer = None,
60796080
videosPath: str = None,
60806081
videoSize: IntSize = None,
60816082
recordHar: RecordHarOptions = None,
@@ -6119,6 +6120,8 @@ def newContext(
61196120
Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See page.emulateMedia(options) for more details. Defaults to '`light`'.
61206121
acceptDownloads : Optional[bool]
61216122
Whether to automatically download all the attachments. Defaults to `false` where all the downloads are canceled.
6123+
proxy : Optional[{"server": str, "bypass": Optional[str], "username": Optional[str], "password": Optional[str]}]
6124+
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' } })`.
61226125
videosPath : Optional[str]
61236126
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.
61246127
videoSize : Optional[{"width": int, "height": int}]
@@ -6151,6 +6154,7 @@ def newContext(
61516154
colorScheme=colorScheme,
61526155
acceptDownloads=acceptDownloads,
61536156
defaultBrowserType=defaultBrowserType,
6157+
proxy=proxy,
61546158
videosPath=videosPath,
61556159
videoSize=videoSize,
61566160
recordHar=recordHar,
@@ -6178,6 +6182,7 @@ def newPage(
61786182
colorScheme: Literal["dark", "light", "no-preference"] = None,
61796183
acceptDownloads: bool = None,
61806184
defaultBrowserType: str = None,
6185+
proxy: ProxyServer = None,
61816186
videosPath: str = None,
61826187
videoSize: IntSize = None,
61836188
recordHar: RecordHarOptions = None,
@@ -6222,6 +6227,8 @@ def newPage(
62226227
Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See page.emulateMedia(options) for more details. Defaults to '`light`'.
62236228
acceptDownloads : Optional[bool]
62246229
Whether to automatically download all the attachments. Defaults to `false` where all the downloads are canceled.
6230+
proxy : Optional[{"server": str, "bypass": Optional[str], "username": Optional[str], "password": Optional[str]}]
6231+
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' } })`.
62256232
videosPath : Optional[str]
62266233
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.
62276234
videoSize : Optional[{"width": int, "height": int}]
@@ -6254,6 +6261,7 @@ def newPage(
62546261
colorScheme=colorScheme,
62556262
acceptDownloads=acceptDownloads,
62566263
defaultBrowserType=defaultBrowserType,
6264+
proxy=proxy,
62576265
videosPath=videosPath,
62586266
videoSize=videoSize,
62596267
recordHar=recordHar,

scripts/expected_api_mismatch.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,3 @@ Parameter not implemented: BrowserContext.addInitScript(arg=)
116116
# OptionsOr
117117
Parameter not implemented: Page.waitForEvent(optionsOrPredicate=)
118118
Parameter not implemented: BrowserContext.waitForEvent(optionsOrPredicate=)
119-
120-
121-
# 1.6 Todo
122-
Parameter not implemented: Browser.newPage(proxy=)
123-
Parameter not implemented: Browser.newContext(proxy=)

0 commit comments

Comments
 (0)