Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore: remove Chromium Windows proxy hacks (#31724)

Max Schmitt1b220c528952
diff --git a/docs/src/api/params.md b/docs/src/api/params.md
index 5aa9c6a5ab..ccd6bae8fe 100644
--- a/docs/src/api/params.md
+++ b/docs/src/api/params.md
@@ -769,12 +769,6 @@ Actual picture of each page will be scaled down if necessary to fit the specifie
Network proxy settings to use with this context. Defaults to none.
-:::note
-For Chromium on Windows the 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: 'http://per-context' } })`.
-:::
-
## context-option-strict
- `strictSelectors` <[boolean]>
diff --git a/docs/src/network.md b/docs/src/network.md
index f1fbc620b3..c7e6bdca1c 100644
--- a/docs/src/network.md
+++ b/docs/src/network.md
@@ -147,7 +147,7 @@ const browser = await chromium.launch({
Browser browser = chromium.launch(new BrowserType.LaunchOptions()
.setProxy(new Proxy("http://myproxy.com:3128")
.setUsername('usr')
- .setPassword('pwd'));
+ .setPassword('pwd')));
```
```python async
@@ -179,60 +179,48 @@ await using var browser = await BrowserType.LaunchAsync(new()
});
```
-When specifying proxy for each context individually, **Chromium on Windows** needs a hint that proxy will be set. This is done via passing a non-empty proxy server to the browser itself. Here is an example of a context-specific proxy:
+Its also possible to specify it per context:
-```js tab=js-test title="playwright.config.ts"
-import { defineConfig } from '@playwright/test';
-export default defineConfig({
- use: {
- launchOptions: {
- // Browser proxy option is required for Chromium on Windows.
- proxy: { server: 'per-context' }
- },
+```js tab=js-test title="example.spec.ts"
+import { test, expect } from '@playwright/test';
+
+test('should use custom proxy on a new context', async ({ browser }) => {
+ const context = await browser.newContext({
proxy: {
server: 'http://myproxy.com:3128',
}
- }
+ });
+ const page = await context.newPage();
+
+ await context.close();
});
```
```js tab=js-library
-const browser = await chromium.launch({
- // Browser proxy option is required for Chromium on Windows.
- proxy: { server: 'per-context' }
-});
+const browser = await chromium.launch();
const context = await browser.newContext({
proxy: { server: 'http://myproxy.com:3128' }
});
```
```java
-Browser browser = chromium.launch(new BrowserType.LaunchOptions()
- // Browser proxy option is required for Chromium on Windows.
- .setProxy(new Proxy("per-context"));
-BrowserContext context = chromium.launch(new Browser.NewContextOptions()
- .setProxy(new Proxy("http://myproxy.com:3128"));
+Browser browser = chromium.launch();
+BrowserContext context = browser.newContext(new Browser.NewContextOptions()
+ .setProxy(new Proxy("http://myproxy.com:3128")));
```
```python async
-# Browser proxy option is required for Chromium on Windows.
-browser = await chromium.launch(proxy={"server": "per-context"})
+browser = await chromium.launch()
context = await browser.new_context(proxy={"server": "http://myproxy.com:3128"})
```
```python sync
-# Browser proxy option is required for Chromium on Windows.
-browser = chromium.launch(proxy={"server": "per-context"})
+browser = chromium.launch()
context = browser.new_context(proxy={"server": "http://myproxy.com:3128"})
```
```csharp
-var proxy = new Proxy { Server = "per-context" };
-await using var browser = await BrowserType.LaunchAsync(new()
-{
- // Browser proxy option is required for Chromium on Windows.
- Proxy = proxy
-});
+await using var browser = await BrowserType.LaunchAsync();
await using var context = await browser.NewContextAsync(new()
{
Proxy = new Proxy { Server = "http://myproxy.com:3128" },
diff --git a/packages/playwright-core/src/server/browserContext.ts b/packages/playwright-core/src/server/browserContext.ts
index 80681130ef..db20728904 100644
--- a/packages/playwright-core/src/server/browserContext.ts
+++ b/packages/playwright-core/src/server/browserContext.ts
@@ -15,7 +15,6 @@
* limitations under the License.
*/
-import * as os from 'os';
import { TimeoutSettings } from '../common/timeoutSettings';
import { createGuid, debugMode } from '../utils';
import { mkdirIfNeeded } from '../utils/fileUtils';
@@ -700,11 +699,8 @@ export function validateBrowserContextOptions(options: channels.BrowserNewContex
options.recordVideo.size!.width &= ~1;
options.recordVideo.size!.height &= ~1;
}
- if (options.proxy) {
- if (!browserOptions.proxy && browserOptions.isChromium && os.platform() === 'win32')
- throw new Error(`Browser needs to be launched with the global proxy. If all contexts override the proxy, global proxy will be never used and can be any string, for example "launch({ proxy: { server: 'http://per-context' } })"`);
+ if (options.proxy)
options.proxy = normalizeProxySettings(options.proxy);
- }
verifyGeolocation(options.geolocation);
}
diff --git a/packages/playwright-core/src/server/chromium/chromium.ts b/packages/playwright-core/src/server/chromium/chromium.ts
index a30be361e7..04177b4690 100644
--- a/packages/playwright-core/src/server/chromium/chromium.ts
+++ b/packages/playwright-core/src/server/chromium/chromium.ts
@@ -110,12 +110,6 @@ export class Chromium extends BrowserType {
artifactsDir,
downloadsPath: options.downloadsPath || artifactsDir,
tracesDir: options.tracesDir || artifactsDir,
- // On Windows context level proxies only work, if there isn't a global proxy
- // set. This is currently a bug in the CR/Windows networking stack. By
- // passing an arbitrary value we disable the check in PW land which warns
- // users in normal (launch/launchServer) mode since otherwise connectOverCDP
- // does not work at all with proxies on Windows.
- proxy: { server: 'per-context' },
originalLaunchOptions: {},
};
validateBrowserContextOptions(persistent, browserOptions);
diff --git a/packages/playwright-core/types/types.d.ts b/packages/playwright-core/types/types.d.ts
index f4baa9a352..9c125fef1e 100644
--- a/packages/playwright-core/types/types.d.ts
+++ b/packages/playwright-core/types/types.d.ts
@@ -9372,10 +9372,6 @@ export interface Browser {
/**
* Network proxy settings to use with this context. Defaults to none.
- *
- * **NOTE** For Chromium on Windows the 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: 'http://per-context' } })`.
*/
proxy?: {
/**
@@ -20847,10 +20843,6 @@ export interface BrowserContextOptions {
/**
* Network proxy settings to use with this context. Defaults to none.
- *
- * **NOTE** For Chromium on Windows the 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: 'http://per-context' } })`.
*/
proxy?: {
/**
diff --git a/tests/library/browsercontext-proxy.spec.ts b/tests/library/browsercontext-proxy.spec.ts
index d56bce0972..c2d9d5b31c 100644
--- a/tests/library/browsercontext-proxy.spec.ts
+++ b/tests/library/browsercontext-proxy.spec.ts
@@ -18,37 +18,12 @@ import { browserTest as it, expect } from '../config/browserTest';
it.skip(({ mode }) => mode.startsWith('service'));
-it.use({
- launchOptions: async ({ launchOptions }, use) => {
- await use({
- ...launchOptions,
- proxy: { server: 'per-context' }
- });
- }
-});
-
-
it.beforeEach(({ server }) => {
server.setRoute('/target.html', async (req, res) => {
res.end('<html><title>Served by the proxy</title></html>');
});
});
-it('should throw for missing global proxy on Chromium Windows', async ({ browserName, platform, browserType, server }) => {
- it.skip(browserName !== 'chromium' || platform !== 'win32');
-
- let browser;
- try {
- browser = await browserType.launch({
- proxy: undefined,
- });
- const error = await browser.newContext({ proxy: { server: `localhost:${server.PORT}` } }).catch(e => e);
- expect(error.toString()).toContain('Browser needs to be launched with the global proxy');
- } finally {
- await browser.close();
- }
-});
-
it('should work when passing the proxy only on the context level', async ({ browserName, platform, browserType, server, proxyServer }) => {
// Currently an upstream bug in the network stack of Chromium which leads that
// the wrong proxy gets used in the BrowserContext.
diff --git a/tests/library/fetch-proxy.spec.ts b/tests/library/fetch-proxy.spec.ts
index b0c921c8e3..f6961e6de5 100644
--- a/tests/library/fetch-proxy.spec.ts
+++ b/tests/library/fetch-proxy.spec.ts
@@ -16,15 +16,6 @@
import { contextTest as it, expect } from '../config/browserTest';
-it.use({
- launchOptions: async ({ launchOptions }, use) => {
- await use({
- ...launchOptions,
- proxy: { server: 'per-context' }
- });
- }
-});
-
it.skip(({ mode }) => mode !== 'default');
it('context request should pick up proxy credentials', async ({ browserType, server, proxyServer }) => {