Skip to content

Commit 00801d0

Browse files
authored
Allow Chrome using http proxy (#522)
1 parent 5553b5f commit 00801d0

2 files changed

Lines changed: 37 additions & 17 deletions

File tree

Readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ If for some reason you don't want to use Docker to run this tool you can run it
238238
## Proxy configuration
239239

240240
Network proxies are configured via the `*_PROXY` and `NO_PROXY` environment variables. Details on the environment variables available from [proxy-from-env](https://github.com/Rob--W/proxy-from-env#environment-variables), and the kinds of proxies avaiable from [proxy-agent](https://github.com/TooTallNate/proxy-agents/tree/main/packages/proxy-agent#maps-proxy-protocols-to-httpagent-implementations).
241+
242+
Set `EPICGAMES_FREEGAMES_NODE_USE_PROXY_CHROME=true` to make Chrome use the proxy server specified by `HTTPS_PROXY`. If `HTTPS_PROXY` is unset, Chrome uses `ALL_PROXY` instead. This setting affects Chrome only; Node.js requests keep their existing proxy behavior.
243+
244+
The application forwards the selected proxy value unchanged to Chrome with `--proxy-server`. It does not parse or normalize the value, apply `NO_PROXY`, or configure proxy authentication. Use a proxy server format Chrome accepts, and do not include credentials because Chrome exposes the argument in its process command line.
241245

242246
## Miscellaneous
243247

src/common/puppeteer.ts

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,38 @@ export function getDevtoolsUrl(page: Page): string {
7878
return `devtools://devtools/bundled/inspector.html?ws=${wsEndpoint.host}/devtools/page/${targetId}`;
7979
}
8080

81-
export const getLaunchArgs = async (): Promise<Parameters<typeof puppeteer.launch>[0]> => ({
82-
executablePath: await executablePath(),
83-
headless: true,
84-
protocolTimeout: 0, // https://github.com/puppeteer/puppeteer/issues/9927
85-
args: [
86-
'--disable-web-security', // For accessing iframes
87-
'--disable-features=IsolateOrigins,site-per-process', // For accessing iframes
88-
'--no-sandbox', // For Docker root user
89-
'--disable-dev-shm-usage', // https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#tips
90-
'--no-zygote', // https://github.com/puppeteer/puppeteer/issues/1825#issuecomment-636478077
91-
'--disable-gpu', // https://github.com/puppeteer/puppeteer/issues/12189#issuecomment-2264825572
92-
// For debugging in Docker
93-
// '--remote-debugging-port=3001',
94-
// '--remote-debugging-address=0.0.0.0', // Change devtools url to localhost
95-
],
96-
});
81+
const getProxyEnvironmentVariable = (name: string): string | undefined =>
82+
[process.env[name.toLowerCase()], process.env[name.toUpperCase()]].find(Boolean);
83+
84+
const CHROME_PROXY_ENABLED_ENVIRONMENT_VARIABLE = 'EPICGAMES_FREEGAMES_NODE_USE_PROXY_CHROME';
85+
86+
const getChromeProxyServer = (): string | undefined => {
87+
if (process.env[CHROME_PROXY_ENABLED_ENVIRONMENT_VARIABLE]?.toLowerCase() !== 'true') {
88+
return undefined;
89+
}
90+
return getProxyEnvironmentVariable('https_proxy') ?? getProxyEnvironmentVariable('all_proxy');
91+
};
92+
93+
export const getLaunchArgs = async (): Promise<Parameters<typeof puppeteer.launch>[0]> => {
94+
const chromeProxyServer = getChromeProxyServer();
95+
return {
96+
executablePath: await executablePath(),
97+
headless: true,
98+
protocolTimeout: 0, // https://github.com/puppeteer/puppeteer/issues/9927
99+
args: [
100+
'--disable-web-security', // For accessing iframes
101+
'--disable-features=IsolateOrigins,site-per-process', // For accessing iframes
102+
'--no-sandbox', // For Docker root user
103+
'--disable-dev-shm-usage', // https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#tips
104+
'--no-zygote', // https://github.com/puppeteer/puppeteer/issues/1825#issuecomment-636478077
105+
'--disable-gpu', // https://github.com/puppeteer/puppeteer/issues/12189#issuecomment-2264825572
106+
...(chromeProxyServer ? [`--proxy-server=${chromeProxyServer}`] : []),
107+
// For debugging in Docker
108+
// '--remote-debugging-port=3001',
109+
// '--remote-debugging-address=0.0.0.0', // Change devtools url to localhost
110+
],
111+
};
112+
};
97113

98114
/**
99115
* This is a hacky solution to retry a function if it doesn't return within a timeout.
@@ -183,7 +199,7 @@ export const safeNewPage = async (browser: Browser, L: Logger): Promise<Page> =>
183199
};
184200

185201
/**
186-
* Launcha new browser within a wrapper that will retry if it hangs for 30 seconds
202+
* Launch a new browser within a wrapper that will retry if it hangs for 30 seconds
187203
*/
188204
export const safeLaunchBrowser = async (L: Logger): Promise<Browser> => {
189205
L.debug('Launching a new browser');

0 commit comments

Comments
 (0)