Detect Chrome Version in Puppeteer
In this article
Discovering the Chrome version used by Puppeteer is essential for debugging, ensuring compatibility with web features, and verifying that automated tests run under the correct browser environment. Puppeteer bundles a specific version of Chromium by default, which may differ from the Chrome version installed on your system. By retrieving the browser's version programmatically, you can confirm which engine is driving your automation tasks. This guide walks you through accurate methods to detect the Chrome or Chromium version managed by Puppeteer, including code examples and best practices.
What You'll Need
- A working Node.js environment (version 14 or higher recommended)
- Puppeteer installed in your project via npm or yarn
- Basic knowledge of JavaScript or TypeScript
- A code editor or terminal to run scripts
Step-by-Step
- Create a new JavaScript file (e.g.,
check-chrome-version.js) in your project directory. This file will contain the script to launch Puppeteer and retrieve version information. - Import the Puppeteer library at the top of the file using
const puppeteer = require('puppeteer');. If you're using ES modules, useimport puppeteer from 'puppeteer';instead. - Write an asynchronous function or use an async IIFE (Immediately Invoked Function Expression) to wrap your Puppeteer code, as Puppeteer methods are promise-based and require an async context.
- Launch a browser instance using
const browser = await puppeteer.launch();. This starts the bundled Chromium binary. No arguments are needed unless you want to customize the launch behavior. - Call
const version = await browser.version();to retrieve the detailed version string of the Chromium instance. This method returns a string like"Chromium/123.0.6312.86"or"HeadlessChrome/123.0.6312.86", depending on headless mode. - Optionally, call
const userAgent = await browser.userAgent();to get the full user agent string. This includes the Chrome version used, which may be labeled as Chrome even though Puppeteer uses Chromium. Look for the patternChrome/\d+\.\d+in the string. - Log both values to the console using
console.log('Version:', version);andconsole.log('User Agent:', userAgent);to view the output. - Close the browser with
await browser.close();to free system resources after retrieving the data. - Run the script from the terminal using
node check-chrome-version.js. The output will display the exact Chromium version Puppeteer is using. - (Optional) To check the revision number bundled with your Puppeteer version, inspect the
package.jsonfile innode_modules/puppeteer/or runnpx puppeteer browsers listif using Puppeteer v20+ to see installed browser binaries.
Common Mistakes
- Assuming Puppeteer uses system Chrome: Puppeteer does not use the Chrome browser installed on your machine by default. It downloads and uses a specific version of Chromium unless configured otherwise.
- Not awaiting asynchronous calls: Forgetting to use
awaitbeforebrowser.version()will result in a promise being logged instead of the actual version string. - Ignoring headless differences: The version string may show "HeadlessChrome" instead of "Chrome", which is normal and does not indicate an error.
- Using outdated Puppeteer versions: Older versions may not support newer Chromium features or version reporting methods. Always keep Puppeteer updated via
npm update puppeteer. - Not closing the browser instance: Failing to call
browser.close()can leave orphaned processes running, consuming memory.
Tips
- Use
puppeteer.launch({ headless: false })during debugging to visually confirm the browser window and version in the title bar or about dialog. - Store the version output in logs when running automated tests to track browser environment changes over time.
- If you need a specific Chrome version, consider using
puppeteer-corewith a custom executable path pointing to your installed Chrome browser. - Combine version detection with CI/CD pipelines to ensure consistent browser versions across development and testing environments.
- Use
process.env.PUPPETEER_CACHE_DIRto control where Chromium is downloaded, making it easier to inspect or reuse binaries.
Troubleshooting
If the script fails to return a version, first verify that Puppeteer is correctly installed by running npx puppeteer --version. If you get a "command not found" error, reinstall Puppeteer using npm install puppeteer. If the browser fails to launch, check for missing system dependencies—Linux systems often require additional libraries like libnss3 or libxss1. On Windows, ensure no antivirus software is blocking the Chromium executable. If browser.version() returns undefined, confirm that you are calling it after puppeteer.launch() and before browser.close(). If the user agent string does not reflect the expected version, ensure no middleware or proxies are modifying HTTP headers. In Docker environments, ensure the container has sufficient privileges and required fonts or libraries installed for headless operation.
Frequently Asked Questions
Does Puppeteer use Chrome or Chromium?
Puppeteer uses a specific version of Chromium downloaded automatically. It is not the same as the Chrome browser installed on your system unless manually configured.
Can I make Puppeteer use my installed Chrome version?
Yes, by launching Puppeteer with the executablePath option pointing to your Chrome installation, such as puppeteer.launch({ executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' }) on macOS.
Why does the version show HeadlessChrome instead of Chrome?
This is normal. When running in headless mode (default), the user agent and version string reflect "HeadlessChrome" to indicate the browser is running without a GUI.
How do I update the Chromium version in Puppeteer?
Update Puppeteer itself using npm update puppeteer. Each Puppeteer version bundles a fixed Chromium revision, so updating the package upgrades the browser engine.
Is the Chrome version the same across all machines?
Yes, for a given Puppeteer version, the bundled Chromium version is consistent across operating systems, ensuring reproducible environments.
Can I run this without launching a browser?
No, you must launch the browser instance to retrieve the version. However, the process is fast and can be automated in scripts or tests.