[PoC] Using playwright in nix-shell

Hey folks :wave:

I’m developing a python web application and would like to use playwright for browser tests.

Playwright needs specific browser versions (and I think they also have custom patches) and usually downloads them itself, which doesn’t work at all on my setup. (I’m on arch linux, but the project manages all dependencies through nix or poetry/npm)

Looking for an answer I found this playwright issue and this project, which helped me understand the situation but didn’t really solve my problem, so I spent a few hours to develop an approach that seems to work. It’s only running a small proof-of-concept test for now, but things are looking good.

I extracted the relevant stuff and put it on github, in case anybody runs into similar challenges.

It’s far from perfect (input appreciated!) but seems to do the job for now.

Happy hacking everone :alien:

6 Likes

Thanks a lot for sharing this! Would you mind making this project available as a flake as well? This way it’ll be easier to re-use from other projects without copying all the code :slight_smile:

Also did you give this a try on Mac (both Intel & ARM) already?

Thanks for this one; is there a reason why we can’t use the bin from ms-playwright and just patchelf that? Because if the firefox-bin versions don’t match what playwright provides it crashes - I’m bypassing this currently by just pinning to the nixpkgs with the correct version, but this isn’t forwards compatible

This approach doesn’t work on mac. We fell back to just having people on mac run playwright install and conditionally setting a variable that skips the conftest.py stuff.

FYI, there’s also nixpkgs#playwright.browsers now, but keeping the versions in sync is probably still a struggle if you install playwright itself via poetry or sth.