Run Puppeteer tests from behind a proxy
Configure Puppeteer to connect to BrowserStack through a corporate proxy using the global-agent npm package.
If your network routes outbound connections through a corporate proxy, your Puppeteer script may not be able to reach the BrowserStack cloud endpoint. The global-agent npm package sets a global HTTP proxy that applies to all outbound requests, including the BrowserStack connection.
Install the global-agent package as a development dependency:
npm i --save-dev global-agent
Set the GLOBAL_AGENT_HTTP_PROXY environment variable with your proxy details before running the tests:
export GLOBAL_AGENT_HTTP_PROXY=http://someuser:test123@127.0.0.1:3128
In this example, 127.0.0.1 is the proxy host, 3128 is the port, someuser is the username, and test123 is the password. Replace these with your actual proxy settings.
Add the global-agent bootstrap call at the top of your test script. The bootstrap() function applies your proxy settings to all outbound connections, including the BrowserStack CDP endpoint:
const { bootstrap } = require('global-agent');
bootstrap();
Then run your test:
node duckduckgo_search_with_proxy.js
A full working example is in the sample repository.
Sample script
The following script shows global-agent configured with a proxy. The bootstrap() call must happen before puppeteer.connect() so the proxy is active when the BrowserStack connection is made:
If the website you want to test is also behind a proxy, set up BrowserStack Local with additional config parameters in addition to the configuration above.
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
Thank you for your valuable feedback!