Can Puppeteer Be Used with the Brave Browser?

I would like to know if it’s feasible to run a Puppeteer script on the Brave browser instead of the standard version of Chromium. Since Brave is based on Chromium, I am aware that launching a Selenium script with Brave is an option. However, is there a way to accomplish this using Puppeteer as well?

Yes, you can use Puppeteer with the Brave browser since it is built on Chromium. The key is to instruct Puppeteer to use the Brave executable instead of the default Chromium. Follow these steps to set it up efficiently:

  1. First, locate the Brave executable on your machine. For instance:
    • On macOS, it might be at /Applications/Brave Browser.app/Contents/MacOS/Brave Browser
    • On Windows, it could be at C:\Program Files (x86)\BraveSoftware\Brave-Browser\Application\brave.exe
  2. Then, in your Puppeteer script, you need to specify this executable path. Here’s a concise example:
const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch({
    executablePath: '/path/to/brave', // replace with your Brave path
    headless: false // set to true if you want to run headless
  });
  const page = await browser.newPage();
  await page.goto('https://example.com');
  // Your additional automation script
  await browser.close();
})();

This setup allows you to use Puppeteer effectively with Brave, making your automation tasks both efficient and easy to manage. Remember to replace /path/to/brave with the correct path to your Brave browser executable.

Indeed, using Puppeteer with Brave is a viable approach due to Brave's Chromium foundation. Aside from the method mentioned, another crucial aspect to consider is handling functionalities specific to Brave. For instance, Brave implements strict privacy measures and potentially blocks elements that might alter how your script interacts with certain pages.

To integrate Puppeteer with Brave, you need to navigate potential deviations in browser behavior. Here’s a concise setup:

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch({
    executablePath: 'C:/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe', // Path to Brave
    headless: false, // Change to true for headless mode
    args: ['--no-sandbox', '--disable-setuid-sandbox'] // Additional settings to handle Brave's security
  });
  const page = await browser.newPage();
  await page.goto('https://example.com');
  // Further actions on the page
  await browser.close();
})();

Using settings like --no-sandbox and --disable-setuid-sandbox helps to bypass some of the restrictions Brave may impose by default, which can be useful for certain automated tasks. However, these settings also lower security, so use them wisely and only if necessary. Furthermore, adapting your scripts to Brave’s specific features, such as enabling/disabling Brave Shields, may be needed for smooth operations.