Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ If for some reason you don't want to use Docker to run this tool you can run it
## Proxy configuration

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).

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.

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.

## Miscellaneous

Expand Down
50 changes: 33 additions & 17 deletions src/common/puppeteer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,38 @@ export function getDevtoolsUrl(page: Page): string {
return `devtools://devtools/bundled/inspector.html?ws=${wsEndpoint.host}/devtools/page/${targetId}`;
}

export const getLaunchArgs = async (): Promise<Parameters<typeof puppeteer.launch>[0]> => ({
executablePath: await executablePath(),
headless: true,
protocolTimeout: 0, // https://github.com/puppeteer/puppeteer/issues/9927
args: [
'--disable-web-security', // For accessing iframes
'--disable-features=IsolateOrigins,site-per-process', // For accessing iframes
'--no-sandbox', // For Docker root user
'--disable-dev-shm-usage', // https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#tips
'--no-zygote', // https://github.com/puppeteer/puppeteer/issues/1825#issuecomment-636478077
'--disable-gpu', // https://github.com/puppeteer/puppeteer/issues/12189#issuecomment-2264825572
// For debugging in Docker
// '--remote-debugging-port=3001',
// '--remote-debugging-address=0.0.0.0', // Change devtools url to localhost
],
});
const getProxyEnvironmentVariable = (name: string): string | undefined =>
[process.env[name.toLowerCase()], process.env[name.toUpperCase()]].find(Boolean);

const CHROME_PROXY_ENABLED_ENVIRONMENT_VARIABLE = 'EPICGAMES_FREEGAMES_NODE_USE_PROXY_CHROME';

const getChromeProxyServer = (): string | undefined => {
if (process.env[CHROME_PROXY_ENABLED_ENVIRONMENT_VARIABLE]?.toLowerCase() !== 'true') {
return undefined;
}
return getProxyEnvironmentVariable('https_proxy') ?? getProxyEnvironmentVariable('all_proxy');
};

export const getLaunchArgs = async (): Promise<Parameters<typeof puppeteer.launch>[0]> => {
const chromeProxyServer = getChromeProxyServer();
return {
executablePath: await executablePath(),
headless: true,
protocolTimeout: 0, // https://github.com/puppeteer/puppeteer/issues/9927
args: [
Comment thread
erickguan marked this conversation as resolved.
'--disable-web-security', // For accessing iframes
'--disable-features=IsolateOrigins,site-per-process', // For accessing iframes
'--no-sandbox', // For Docker root user
'--disable-dev-shm-usage', // https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#tips
'--no-zygote', // https://github.com/puppeteer/puppeteer/issues/1825#issuecomment-636478077
'--disable-gpu', // https://github.com/puppeteer/puppeteer/issues/12189#issuecomment-2264825572
...(chromeProxyServer ? [`--proxy-server=${chromeProxyServer}`] : []),
// For debugging in Docker
// '--remote-debugging-port=3001',
// '--remote-debugging-address=0.0.0.0', // Change devtools url to localhost
],
};
};

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

/**
* Launcha new browser within a wrapper that will retry if it hangs for 30 seconds
* Launch a new browser within a wrapper that will retry if it hangs for 30 seconds
*/
export const safeLaunchBrowser = async (L: Logger): Promise<Browser> => {
L.debug('Launching a new browser');
Expand Down