Run Playwright Scripts in Google Chrome: Step-by-Step
In this article
This guide shows you how to execute Playwright test scripts specifically in Google Chrome (instead of the default Chromium browser). Playwright supports Chrome via the channel: 'chrome' option, which uses your installed Chrome browser. This is useful when you need to test against the exact Chrome version your users have, or when you want to leverage Chrome-specific features. You'll need Node.js, npm, and a basic Playwright project set up.
What You'll Need
- Node.js (version 16 or later) installed on your system.
- Google Chrome installed (any recent stable version).
- A code editor (like VS Code) and a terminal.
- Basic familiarity with JavaScript/Node.js.
Step-by-Step
- Create a new project directory (if you don't have one):
mkdir playwright-chrome-example cd playwright-chrome-example - Initialize a Node.js project (accept defaults):
npm init -y - Install Playwright:
npm install @playwright/testThis installs the Playwright test runner and its libraries.
- Install the Chrome browser (if not already installed):
npx playwright install chromeThis ensures Playwright can find Chrome. It downloads the browser if needed, but it will use your system Chrome when you specify
channel. - Create a test file (e.g.,
example.spec.js):const { test, expect } = require('@playwright/test'); test('open Google in Chrome', async ({ page }) => { await page.goto('https://www.google.com'); await expect(page).toHaveTitle(/Google/); }); - Configure Playwright to use Chrome in
playwright.config.js(create if missing):const { defineConfig } = require('@playwright/test'); module.exports = defineConfig({ use: { channel: 'chrome', // this tells Playwright to use Google Chrome }, });Alternatively, you can specify the channel per project or per test.
- Run the test:
npx playwright testPlaywright will launch Google Chrome (not Chromium) and execute the test.
- Run in headed mode (to see the browser window):
npx playwright test --headed
Common Mistakes
- Forgetting to set
channel: 'chrome'– without this, Playwright uses bundled Chromium. - Running
npx playwright installwithout specifyingchrome– this only downloads Chromium, not Chrome. Usenpx playwright install chrome. - Using
channel: 'chrome-beta'when you have stable Chrome installed – that will fail. Use the correct channel name for your installed version. - Not closing the browser properly – Playwright handles this automatically, but if you manually launch browsers, ensure you call
close().
Tips
- Use
channel: 'chrome'in your config to make all tests run in Chrome by default. - For debugging, run with
--headedand addpage.pause()in your test to open the Playwright inspector. - Use
--project=chromiumif you have multiple projects defined, but ensure that project haschannel: 'chrome'. - If you need to test Chrome on a specific operating system, use Playwright's Docker images or CI environments with Chrome pre-installed.
Troubleshooting
- Error: "Executable doesn't exist" or "browserType.launch: Executable doesn't exist" – This means Playwright can't find Chrome. Run
npx playwright install chromeagain, or ensure Chrome is installed in a standard location. - Error: "Channel 'chrome' not found" – This usually means Chrome is not installed or the channel name is wrong. Check your Chrome installation and use
chromefor stable,chrome-betafor beta,chrome-devfor dev,chrome-canaryfor canary. - Chrome launches but tests fail with network errors – This may be due to Chrome's sandbox. If you're running as root or in a container, you may need to launch with
--no-sandbox(not recommended for production). In Playwright, you can pass launch options in config:use: { launchOptions: { args: ['--no-sandbox'] } }. - Tests run in Chromium instead of Chrome – Double-check your config file is being read. Ensure you're in the project root and the config file is named
playwright.config.jsorplaywright.config.ts.
Frequently Asked Questions
Can I use Chrome for only some tests?
Yes, you can define multiple projects in playwright.config.js. One project can use channel: 'chrome' and another can use the default Chromium. Then run tests with --project=chrome.
What's the difference between Chromium and Chrome in Playwright?
Chromium is the open-source browser that Chrome is based on. Playwright downloads its own Chromium build. Chrome is Google's proprietary browser with additional codecs and features. Using channel: 'chrome' ensures you're testing against the exact Chrome you have installed.
Do I need to install Chrome separately?
Yes, you need Google Chrome installed on your system. Playwright will not download Chrome automatically; you must install it or run npx playwright install chrome which will download it if you don't have it.
Can I use Chrome in headless mode?
Yes, Playwright runs Chrome in headless mode by default. To see the UI, use --headed.
Why does my test run slower in Chrome than Chromium?
Chrome is a heavier browser with more features. Performance differences are usually minimal, but if you notice significant slowdowns, check for extensions or background processes in your Chrome profile. You can also use a clean profile by setting launchOptions: { args: ['--user-data-dir=/tmp/playwright-chrome'] }.
How do I run a single test file in Chrome?
Use npx playwright test example.spec.js – it will use the config's channel setting.