playwright
playwright copied to clipboard
[BUG] webServer uses proxy settings in .yarnrc for v1.13.2+ when running via yarn
System info
- Playwright Version: [v1.31.2 to v1.34.0] All versions are tested with corresponding image and npm package version.
- Operating System: [Docker playwright:v1.34.0, etc]
- Other info:
Source code
- [x] I provided exact source code that allows reproducing the issue locally.
Config file
// playwright.config.ts
import { defineConfig, devices } from '@playwright/test';
export default defineConfig({
webServer: {
command: 'node ./start-server.js',
url: 'http://localhost:10039', // I also tested with 127.0.0.1 with the same result.
timeout: 120 * 1000,
reuseExistingServer: false
},
use: {
baseUrl: 'http://localhost:10039'
}
});
/etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
...
$http_proxy, $https_proxy, $no_proxy, and their upper case versions are all unset.
.yarnrc includes proxy and https-proxy settings.
Steps
- Run
DEBUG=pw:webserver npx playwright test
Expected
Ignore other proxy envs (like npm_config_proxy) other than http_proxy, https_proxy to match browser behavior.
Playwright v.1.31.1 and below.
$ npx playwright test
[timestamp] pw:server HTTP GET: http://localhost:10039/
[timestamp] pw:server Error while checking if http://localhost:10039/ is available: connect ECONNREFUSED ::1:10039
[timestamp] pw:server Starting WebServer process node ./start-server.js
[timestamp] pw:server Process started
[timestamp] pw:server Waiting for availability...
[timestamp] pw:server HTTP GET http://localhost:10039/
[timestamp] pw:server Error while checking if http://localhost:10039/ is available: connect ECONNREFUSED ::1:10039
[timestamp] pw:server Waiting 100ms
...
[timestamp] pw:server HTTP GET: http://localhost:10039/
[around 20s] pw:server HTTP Status: 200
[timestamp] pw:server WebServer available
Actual
Network pinging uses other proxy envs (like npm_config_proxy) other than http_proxy, https_proxy.
Playwright v1.31.2 and above. I am only able to reproduce it in our company's GitLab CI K8S environment. I tried reproducing it locally (Podman container) and v1.31.2 and above works fine.
$ npx playwright test
[timestamp] pw:server HTTP GET: http://localhost:10039/
[timestamp] pw:server HTTP Status: 407
[timestamp] pw:server Starting WebServer process node ./start-server.js
[timestamp] pw:server Process started
[timestamp] pw:server Waiting for availability...
[timestamp] pw:server HTTP GET http://localhost:10039/
[timestamp] pw:server HTTP Status: 407
[timestamp] pw:server Waiting 100ms
...
[timestamp] pw:server HTTP GET: http://localhost:10039/
[timestamp] pw:server HTTP Status: 407
Error: Timed out waiting 120000ms from config.webServer.
error Command failed with exit code 1.
Seeing the changes of v1.31.2 related to webServer (#21227), I made my own debug script. But my script runs fine in v1.31.2 and above:
test-server.js
const utils = require('playwright-core/lib/utils');
const {httpRequest} = utils;
httpRequest(
{
url: 'http://localhost:10039/',
headers: {Accept: '*/*'},
rejectUnauthorized: true,
},
res => {
res.resume();
const statusCode = res.statusCode;
console.log(statusCode);
let body = '';
res.on('data', chunk => { body += chunk; };
res.on('end', () => { console.log(body); });
},
console.error,
)
/*
node ./start-server.js &
sleep 30
node ./test-server.js
*/
/*
200
<!doctype html>...
*/
Removing webServer config and running this also works fine:
node ./start-server.js &
sleep 30
npx playwright test
I found the issue, v1.31.2+ uses .yarnrc's configuration for proxy
and https-proxy
. We specified them for package download, but did not expect them to take effect for playwright's CLI when running through yarn yarn test
("test": "npx playwright test"
) instead of npx playwright test
. Is this behavior expected or out of bound for a playwright issue?
I have updated issue's title.
@danvim Yes, this is an expected behavior; the yarnrc
defines proxy settings for all the commands that yarn runs.