User Agents

Web browsers and everyday web tech, explained

Run Playwright Tests in Chrome with the chrome Channel

· 5 min read · Browsers

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Running Playwright tests in Google Chrome (instead of the bundled Chromium) is useful when you need to test against the exact browser your users have, or when you rely on Chrome-specific features like proprietary codecs or extensions. This guide shows you how to configure Playwright to use the installed Chrome browser via the channel: 'chrome' option, and how to run your tests with it.

What You'll Need

  • A Node.js project with Playwright installed (npm init playwright@latest or npm install @playwright/test).
  • Google Chrome installed on your system (stable channel). Playwright will not download Chrome; it uses your existing installation.
  • Basic familiarity with the command line and your test files.

Step-by-Step

  1. Verify Chrome is installed – Check that Google Chrome is present. On Windows, look in C:\Program Files\Google\Chrome\Application\chrome.exe; on macOS, /Applications/Google Chrome.app; on Linux, run which google-chrome or which google-chrome-stable.
  2. Open your Playwright config file – This is typically playwright.config.ts (or .js) in the project root. You'll edit the projects section.
  3. Add or modify a project to use the Chrome channel – Inside the projects array, add an entry like this:
    {
      name: 'Google Chrome',
      use: {
        channel: 'chrome',
      },
    }
    If you already have a project named 'chromium', you can either change its channel or add a new one. The channel property tells Playwright to launch the real Chrome instead of the bundled Chromium.
  4. Set other options as needed – You can combine the channel with other use options like headless: false to see the browser, or viewport for a specific screen size. For example:
    {
      name: 'Chrome headed',
      use: {
        channel: 'chrome',
        headless: false,
      },
    }
  5. Save the config file – Ensure the JSON/JS syntax is valid. If you're using TypeScript, the config is a TS file, so type-check it if needed.
  6. Run your tests with the Chrome project – Use the command-line flag to select the project:
    npx playwright test --project="Google Chrome"
    If you only have one project and it uses the chrome channel, simply run npx playwright test.
  7. Verify that Chrome is actually used – When you run the test, look at the browser window (if headed) or check the console output. Playwright will show the browser name as 'chromium' even when using the channel, but you can confirm by checking the user agent or by opening DevTools in the launched browser. A quick way is to add a test that prints await page.evaluate(() => navigator.userAgent) – it will contain Chrome/ and not HeadlessChrome/ if you're using the real Chrome.

Common Mistakes

  • Forgetting to install Chrome – If Chrome is not installed, Playwright will throw an error saying it cannot find the executable. Install Chrome from google.com/chrome.
  • Using the wrong channel name – The channel for stable Chrome is 'chrome'. For Chrome for Testing, it's 'chrome-beta', 'chrome-dev', or 'chrome-canary'. Using an invalid name will cause an error.
  • Setting channel globally but expecting it to apply to all projects – If you set channel: 'chrome' in the top-level use block, it applies to all projects. That's fine, but if you have multiple projects, they will all use Chrome. Make sure that's what you want.
  • Not specifying the project when running – If you have multiple projects and you don't use --project, Playwright runs all of them. If you only want Chrome, use the flag.
  • Assuming the bundled Chromium is replaced – The channel option does not uninstall or replace the bundled Chromium; it just tells Playwright to launch a different browser for that project.

Tips

  • Use a dedicated project for Chrome – This keeps your default Chromium tests intact and lets you run Chrome-specific tests separately.
  • Combine with headless: false for debugging – When you need to see what's happening, run Chrome in headed mode. It's often more representative of user behavior.
  • Use environment variables for flexibility – You can set the channel via an environment variable if you want to switch without editing the config. For example, in your config: channel: process.env.BROWSER_CHANNEL || 'chromium'.
  • Keep Chrome updated – Playwright's automation works best with recent Chrome versions. If you see unexpected failures, update Chrome.
  • Check the Playwright version – The channel option is supported since Playwright 1.0. If you have an older version, update to the latest.

Troubleshooting

  • Error: "Executable doesn't exist" – Playwright cannot find Chrome. Make sure Chrome is installed in a standard location. If it's installed elsewhere, you can specify the full path using the executablePath option instead of channel.
  • Error: "Channel 'chrome' is not recognized" – This usually means Playwright is outdated or the channel name is misspelled. Run npm update @playwright/test and double-check the spelling.
  • Tests pass in Chromium but fail in Chrome – This could be due to slight rendering differences or Chrome-specific security features. Inspect the failure screenshots or videos. You might need to adjust your tests or use Chrome-specific capabilities.
  • Chrome launches but tests hang – Sometimes Chrome's first-run dialog or a profile issue can cause problems. Try running with a fresh user-data-dir: add launchOptions: { args: ['--user-data-dir=/tmp/chrome-test'] } to the project's use.
  • Headless mode doesn't work with Chrome – Playwright supports headless mode with Chrome, but you might need to use headless: true (default). If you see errors, try headless: false to see if it's a headless-specific issue.

Frequently Asked Questions

What is the difference between 'chromium' and 'chrome' channel?

The default 'chromium' uses the Chromium build that Playwright downloads. The 'chrome' channel uses your installed Google Chrome browser, which may have proprietary features and different build flags.

Do I need to install Playwright's browsers if I use the chrome channel?

No, for the chrome channel you don't need to run npx playwright install for Chrome. However, you may still need the other browsers if your config uses them.

Can I use Chrome for Testing (CfT) with Playwright?

Yes, you can use channels like chrome-beta, chrome-dev, or chrome-canary. These correspond to Chrome for Testing builds. You can also download them via npx playwright install chrome.

Will my tests run faster with the chrome channel?

Not necessarily. Performance is similar, but if you have a specific Chrome version that you need to test against, the channel ensures consistency.

How do I run tests in both Chromium and Chrome?

Define two projects in your config: one with no channel (default Chromium) and one with channel: 'chrome'. Then run npx playwright test to run both.

Can I use the chrome channel in CI/CD?

Yes, but you must ensure Chrome is installed in the CI environment. Many CI images have Chrome pre-installed. If not, you can install it during the setup step.