Anda bisa Bahasa Indonesia? Baca artikel terjemahannya di sini!
The other day I was tasked to write automated tests for a feature that I had developed. The tests are run using Playwright, and the tests need to open a browser in order to simulate usage. The default browser of choice was Chromium. By default, Playwright is able to take care of the installation for you, but unfortunately, it didn’t work on mine. Instead of seeing a new browser window, I got the following error:
TargetClosedError: Target page, context or browser has been closed
Fortunately, I managed to fix it. In this short article, I’m going to explain how I solved it.
Root Cause
After a brief research, it seems that Chromium developers don’t follow a process called notarization, which, long story short, is a process to register your application to Apple for checking so they can verify that no malicious component is present. You can read more about it here.
However, applying for notarization seems to require an Apple Developer Account (source), which costs $99 a year. It’s perfectly understandable if a non-profit developer can’t justify the cost, let alone a browser that’s mainly aimed for developers (we got Google Chrome for the masses instead), but unfortunately, macOS will refuse to run these apps by default.
Solution
The first thing we need to do is to directly install Chromium using Homebrew with a special flag. Make sure you’ve installed Homebrew, then run the following command:
brew install chromium --no-quarantine
The above command will set a special attribute to the Chromium executable that will “bypass” the security checking.
Once the installation the complete, replace the original Chromium in Playwright’s browser directory (should be in ~/Library/Caches/ms-playwright/chromium-<VERSION>/chrome-mac
) with the one you just installed (should be copied into Applications
folder). Once replaced, verify that you can open the application by double clicking the executable. If you can, then you’re all good, and your test should be able to open the browser now.
Well, I guess that’s all for now, Folks! Hopefully this little tip can help you if you have the same problem. If you have questions, as usual, feel free to ask away in the comment section below. Finally, thanks for reading, and see you in the next article!😁