Use this on Chrome for using osmesa
sudo apt-get install libosmesa
sudo ln -s /usr/lib/x86_64-linux-gnu/libOSMesa.so.6 /opt/google/chrome/libosmesa.so
google-chrome --no-first-run --user-data-dir=~/chrome-stuff --use-gl=osmesa
Warning: If your using osmesa, the entire page will be rendered with osmesa thus making it slow. So, if you can run tests that do not need WebGL, then this is preferable.
You might also want to know that Chrome itself uses osmesa to headless test. But not all versions. Check out the suported versions here: https://source.chromium.org/chromium/chromium/src/+/main:third_party/mesa/README.chromium;drc=51556bb7b468ff3bb5e998f69388b82a3633798f
Or else, for running headless in general, you can use this: https://gist.github.com/addyosmani/5336747