Rayrun

How do I configure Playwright to work with Docker containers and internal networks or proxies?

Answer

To configure Playwright to work with Docker containers and internal networks or proxies, follow these steps:

Step 1: Set up a proxy server

If your company uses an internal proxy, set the HTTPS_PROXY environment variable before installing Playwright:

HTTPS_PROXY=https://192.0.2.1 npx playwright install

For untrusted custom certificate authorities (CA), set the NODE_EXTRA_CA_CERTS environment variable:

export NODE_EXTRA_CA_CERTS="/path/to/cert.pem"

Step 2: Use an internal artifact repository

Set the PLAYWRIGHT_DOWNLOAD_HOST environment variable to download browser binaries from an internal repository:

PLAYWRIGHT_DOWNLOAD_HOST=192.0.2.1 npx playwright install

For per-browser download hosts, use PLAYWRIGHT_CHROMIUM_DOWNLOAD_HOST, PLAYWRIGHT_FIREFOX_DOWNLOAD_HOST, and PLAYWRIGHT_WEBKIT_DOWNLOAD_HOST.

Step 3: Opt for hermetic installs

Place binaries in local folders by setting the PLAYWRIGHT_BROWSERS_PATH environment variable:

PLAYWRIGHT_BROWSERS_PATH=0 npx playwright install # Binaries in node_modules/playwright-core/.local-browsers folder

For a shared location, specify the folder:

PLAYWRIGHT_BROWSERS_PATH=$HOME/pw-browsers npx playwright test # Binaries in $HOME/pw-browsers folder

By following these steps, you'll be able to run tests using Playwright within Docker containers without browser availability or compatibility issues. For more information on Playwright testing, check out Mastering Playwright Test Automation: Your Comprehensive Cheat Sheet.

Thank you!
Was this helpful?
Still have questions?

If you still have questions, please ask a question and I will try to answer it.

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.