Install Puppeteer Extra and Fix Missing Chrome Errors
In this article
Installing puppeteer-extra allows you to extend the core Puppeteer library with powerful plugins, most notably the stealth plugin, which prevents websites from detecting that the browser is being controlled by an automated script. This setup is essential for web scraping and automation tasks where bot detection is a hurdle. By combining the core Puppeteer engine with the extra wrapper, you gain access to a modular ecosystem that makes your automation scripts more resilient and human-like.
What You'll Need
- Node.js installed on your system (LTS version recommended).
- npm (Node Package Manager) or yarn.
- A code editor such as Visual Studio Code.
- Administrative privileges on your operating system to install system-level dependencies if you are using Linux.
- An active internet connection to download the Chromium binaries.
Step-by-Step
- Initialize Your Project: Open your terminal or command prompt and navigate to your desired project folder. Run
npm init -yto create apackage.jsonfile. This ensures that all dependencies you install are tracked and can be easily replicated in other environments. - Install Puppeteer and Puppeteer-Extra: You need both the core library and the wrapper. Run the following command:
npm install puppeteer puppeteer-extra. Thepuppeteer-extrapackage acts as a proxy, allowing you to use the same API as standard Puppeteer while adding the ability to load plugins. - Install the Stealth Plugin: To avoid detection, install the most common plugin for the extra wrapper:
npm install puppeteer-extra-plugin-stealth. This plugin modifies the browser's fingerprint, hiding properties likenavigator.webdriverand mimicking real browser behavior. - Configure the Script: Create a JavaScript file (e.g.,
index.js). Instead of requiringpuppeteer, you must requirepuppeteer-extra. Add the following code to your script:const puppeteer = require('puppeteer-extra'); const StealthPlugin = require('puppeteer-extra-plugin-stealth'); puppeteer.use(StealthPlugin());This tells the wrapper to apply the stealth modifications before the browser is launched. - Launch the Browser: Initialize the browser using the standard
puppeteer.launch()method. For debugging, it is recommended to setheadless: falseso you can see the browser window and verify that the pages are loading correctly. - Verify the Installation: Run your script using
node index.js. If the browser opens and navigates to a page without immediate blocking or crashes, the installation was successful. - Handle the Missing Chrome Error: If you encounter an error stating that the executable path is missing or Chrome cannot be found, you must explicitly tell Puppeteer where the browser is located. Find the path to your installed Chrome or Chromium browser. On Windows, this is typically in
C:\Program Files\Google\Chrome\Application\chrome.exe. On macOS, it is usually/Applications/Google Chrome.app/Contents/MacOS/Google Chrome. - Update the Launch Configuration: Modify your
puppeteer.launchobject to include theexecutablePathproperty:const browser = await puppeteer.launch({ headless: false, executablePath: 'C:\Program Files\Google\Chrome\Application\chrome.exe' });Replace the path with the actual path found in step 7. This bypasses the default bundled Chromium and uses your system's installed browser.
Common Mistakes
One of the most frequent errors is importing puppeteer instead of puppeteer-extra. If you use const puppeteer = require('puppeteer'), the puppeteer.use() method will be undefined, and your plugins will not load. Always ensure the wrapper is the primary import.
Another common mistake is forgetting to install the stealth plugin separately. Users often assume that puppeteer-extra includes all plugins by default, but it is a modular system. You must install each plugin (like stealth or adblocker) as its own npm package.
Incorrect path formatting in the executablePath is a recurring issue on Windows. Because backslashes are escape characters in JavaScript strings, you must use double backslashes (\\) or forward slashes (/) to define the path to the Chrome executable. Failing to do this will result in a "Path not found" error.
Running Puppeteer as a root user on Linux without the --no-sandbox flag is another common pitfall. Chromium's sandbox security feature often prevents it from launching under the root account, leading to a crash immediately after the launch command is called.
Tips
To increase the longevity of your automation scripts, avoid using a fixed user agent. While the stealth plugin helps, rotating user agents using a library like user-agents can further reduce the risk of being flagged as a bot. Integrate this by passing the userAgent string into page.setUserAgent() after the page is created.
For better performance, use the headless: 'new' mode in recent versions of Puppeteer. This provides a more accurate representation of the browser's behavior compared to the old headless mode, while still maintaining the speed of a background process.
When dealing with sites that have heavy anti-bot protections, try adjusting the viewport size to match common monitor resolutions (e.g., 1920x1080). An unusual or default Puppeteer window size (like 800x600) can be a signal to servers that the visitor is an automated script.
If you are deploying your script to a server (like Ubuntu), ensure you install the necessary system dependencies. Chromium requires several shared libraries (like libX11 and libXcomposite) that are not always present in minimal server images. Using a tool like puppeteer-core can help reduce the image size if you provide the browser externally.
Troubleshooting
If you receive a "Protocol Error: Target Closed" message, it usually indicates that the browser crashed before the script could interact with it. This is often caused by a version mismatch between the Puppeteer library and the installed browser. To fix this, update both to the latest versions using npm update.
When faced with a "Failed to launch the browser process" error on Linux, the most effective solution is to install the missing dependencies. Run sudo apt-get install -y libgbm-dev libnss3 libatk-bridge2.0-0 libgtk-3-0. These are the most common missing libraries that prevent Chromium from initializing.
If the stealth plugin is not working and you are still being detected, check if the website is using advanced TLS fingerprinting. In such cases, simply changing the user agent or using the stealth plugin may not be enough. You may need to investigate puppeteer-extra-plugin-stealth updates or use a proxy that handles TLS termination to mimic a real browser's handshake.
For memory leak issues where the browser consumes all available RAM, ensure you are calling await browser.close() in a finally block. If your script crashes before reaching the close command, orphaned Chrome processes will remain in the background. Use a task manager or the pkill chrome command on Linux/Mac to clear these processes.
Frequently Asked Questions
What is the difference between Puppeteer and Puppeteer Extra?
Puppeteer is the core library developed by Google to control Chrome. Puppeteer Extra is a wrapper that allows you to add plugins, such as the stealth plugin, to modify the browser's behavior without altering the core library.
Why do I still get detected even with the stealth plugin?
The stealth plugin hides common bot indicators, but it cannot hide your IP address or TLS fingerprint. If a site sees 1,000 requests per minute from a single IP, it will block you regardless of the stealth plugin.
Can I use Puppeteer Extra with Brave or Edge?
Yes, as long as the browser is Chromium-based. You simply need to point the executablePath in the launch options to the location of the Brave or Edge executable on your machine.
Do I need to install Chrome separately if I use Puppeteer?
By default, Puppeteer downloads a compatible version of Chromium. However, if you encounter "missing browser" errors or need specific features of the full Chrome browser, installing Chrome separately and linking it via executablePath is recommended.
Is puppeteer-extra-plugin-stealth free to use?
Yes, it is an open-source plugin available via npm and is free for both personal and commercial use under the MIT license.
How do I update the stealth plugin?
You can update the plugin by running npm install puppeteer-extra-plugin-stealth@latest in your project directory to ensure you have the latest bypasses for bot detection.