DEV Community

Coder
Coder

Posted on

How to fix M1 Mac Puppeteer chromium arm64 bug

If you're a Mac user and you're a fan of Puppeteer, you're probably aware of the bug that affects M1 Macs when running Chromium. The issue arises when users try to run Puppeteer on M1 Macs, resulting in an Arm64 bug that prevents code execution. This has been a major issue for many developers who rely on Puppeteer for their automation testing.

Fortunately, there's a solution to this M1 Mac Puppeteer Chromium Arm64 bug, and we're going to explore it in this tutorial.

What Causes the Arm64 Bug in M1 Macs?

The arm64 bug occurs in M1 Macs because of the underlying architecture change in these devices. Since M1 Macs are built on Apple's own ARM-based architecture, they rely on a different instruction set compared to their Intel-based predecessors.

This architecture change means that many applications, including Puppeteer, need to be updated to support the new M1 Macs. This lack of support results in the Arm64 bug that prevents code execution when running Puppeteer with Chromium on M1 Macs.

Fixing the M1 Mac Puppeteer Chromium Arm64 Bug

There are a few steps you need to follow to fix the M1 Mac Puppeteer Chromium Arm64 bug, and we'll take you through each step.

Step 1: Install Xcode Command Line Tools

The first step is to install the Xcode Command Line Tools. You can do this by opening your terminal and typing in the following command:

xcode-select --install
Enter fullscreen mode Exit fullscreen mode

This command will prompt you to install the Xcode Command Line Tools, and you can follow the prompts to complete the installation.

Step 2: Install Homebrew

The next step is to install Homebrew. Homebrew is a package manager that makes it easy to install and manage software on your Mac. You can install Homebrew by typing in the following command in your terminal:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Enter fullscreen mode Exit fullscreen mode

This command will install Homebrew on your Mac. You can verify the installation by typing in the following command:

brew doctor
Enter fullscreen mode Exit fullscreen mode

Step 3: Install Chromium and Puppeteer-Firefox

The third step is to install Chromium and Puppeteer-Firefox. You can do this by running the following commands in your terminal:

brew install --cask chromium
Enter fullscreen mode Exit fullscreen mode
npm install --save-dev puppeteer-firefox
Enter fullscreen mode Exit fullscreen mode

These commands will install Chromium and Puppeteer-Firefox to your Mac.

Step 4: Install Rosetta 2

The fourth step will require you to install Rosetta 2. Since Puppeteer doesn't yet have native support for M1 Macs, we need to emulate an Intel-based environment to run Chromium on M1 Macs. You can install Rosetta 2 by entering the following command:

softwareupdate --install-rosetta
Enter fullscreen mode Exit fullscreen mode

Alternatively, you can also install Rosetta 2 by running any Intel-based application on your M1 Mac. Your Mac will prompt you to install Rosetta 2, and you can follow the prompts to complete the installation.

Step 5: Configure Puppeteer

The fifth and final step is to configure Puppeteer to use Chromium instead of Chrome. You can do this by opening your Puppeteer script and updating the launch configuration to look like the following:

const browser = await puppeteer.launch({
  headless: true,
  executablePath: '/Applications/Chromium.app/Contents/MacOS/Chromium',
  // executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
  args: ['--no-sandbox', '--disable-setuid-sandbox']
});
Enter fullscreen mode Exit fullscreen mode

This configuration tells Puppeteer to use Chromium instead of Chrome when launching a browser instance.

Conclusion

We hope this tutorial has been helpful in fixing the M1 Mac Puppeteer Chromium Arm64 bug. While it may seem complex, these steps are crucial to ensure that you can continue using Puppeteer for automation testing on your M1 Mac.

By installing Xcode Command Line Tools, Homebrew, and Rosetta 2, as well as configuring Puppeteer to use Chromium, you'll be able to run your automation tests without any issues.

If you face any other issues or have any questions, you can refer to Puppeteer's official Github repository for more information.

Top comments (0)