Urgent.News

What's breaking now, across thousands of outlets.

Tech

Fixing "error while loading shared libraries: libnspr4.so" for Playwright with no root access

I was setting up browser automation for an AI coding agent running in a locked-down sandbox this week — no sudo , no passwordless root, nothing. npx playwright install --with-deps chromium failed immediately, and running the browser directly threw this: error while loading shared libraries: libnspr4.so: cannot open shared object file: No such file or directory followed by the same error for…

In a locked-down sandbox environment, where no sudo or passwordless root access is permitted, setting up browser automation using Playwright proved to be a challenging task. The command npx playwright install --with-deps chromium failed immediately, and even running the browser directly resulted in an error message: "error while loading shared libraries: libnspr4.so: cannot open shared object file: No such file or directory."

This issue is a recurring problem in restricted environments such as containers, CI runners, and platforms like Render, Replit, and Streamlit Cloud, where users do not have control over the base image and cannot install anything using apt.

The root cause of this problem lies in the fact that both playwright install --with-deps and playwright install-deps rely on apt-get install, which requires root access. However, in a sandbox environment where no root access is available, neither apt-get install nor apt-get download can be used to install or fetch the necessary libraries.

The solution to this problem is to utilize apt-get download, which does not require root access, and then use dpkg-deb -x to unpack the .deb file into a directory that the user has control over.

To automate this process, a small script was developed that dynamically discovers the package list required by Playwright, downloads each package using apt-get download, and unpacks the contents of the .deb files into a local prefix directory using dpkg-deb -x. This local prefix directory can then be pointed to by the browser using the LD_LIBRARY_PATH environment variable.

By doing so, no changes are made to the /usr directory, no sudo access is required, and the process can be easily undone by simply deleting the local prefix directory.

This rootless approach to setting up Playwright has been packaged into a script (https://github.com/LooseChangeLabs/rootless-playwright) that can be easily installed with the command ./install.sh chromium. The script is MIT-licensed and freely available for anyone facing the same error. By using this script, users can avoid the time-consuming trial-and-error process of manually running the steps required to resolve the issue.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

When two sensors disagree, rank them

GPS said the car was moving. The accelerometer said the phone had not twitched in ten minutes. Asking a sensor to check itself Stationary drift is the oldest problem in location tracking.

Apple iPhone 18 Pro Max Hands On: Maximum Mass

Apple has officially announced its latest crop of smartphones, and this time, the lineup comprises two Pro models and the tech giant’s first ever foldable. Now, the iPhone Duo won’t be arriving on our shores just yet, but that just leaves time for us to get acquainted with the iPhone 18 Pro Max.

More from Friday 18 September →