Skip to content

[BUG] Can't run Playwright in Nix #5501

Closed

Description

@VaasRamsay

Context:

  • Playwright Version: 1.8.0
  • Operating System: Linux
  • Node.js version: 12
  • Browser: All

Describe the bug

Running Playwright in Nix Shell throws missing dependencies error. Even after explicitly adding the missing dependencies suggested by "launch doctor", the same error is thrown.

Error: browserType.launch: Host system is missing dependencies!
--
  | Missing libraries we didn't find packages for:
  | libexpat.so.1
  | libxshmfence.so.1

Probably, I'm hitting this error from here. Nix has it's own ldconfig and it's not found in sbin.

Activity

  1. aslushnikov commented on Feb 19, 2021

    @aslushnikov
    Contributor

    @SamBreaksThings we don't support Nix at the moment and this is the first request we've received regarding it so far.

    So until there's a huge demand for Nix support, this will be low-pri for us. Is there something easy we can do to enable you use Playwright on Nix?

  2. uri-canva commented on Feb 22, 2021

    @uri-canva

    Is it possible to make the linked workaround configurable:

    // NOTE: Using full-qualified path to `ldconfig` since `/sbin` is not part of the
    // default PATH in CRON.
    // @see https://github.com/microsoft/playwright/issues/3397
    const {stdout, code, error} = await spawnAsync('/sbin/ldconfig', ['-p'], {});
    ?

    Note the commit message of aslushnikov@aa3019b

    To the best of my knowledge, ldconfig is always located at /sbin.

    This is one case where it's not located there, and loading it from there leads to broken behaviour.

  3. joscha commented on Feb 22, 2021

    @joscha

    Is it possible to make the linked workaround configurable:

    maybe via an env var await spawnAsync(process.env.LDCONFIG_PATH || '/sbin/ldconfig', ['-p'], {});

    ? Or if that is an unwanted API it would also be thinkable to make it a fallback from the generic ldconfig (w/o qualified path, e.g. command -v ldconfig or which ldconfig) and if that one is not found to fall back to /sbin/ldconfig. Or if we want to make the speed sacrifice for more exotic users of this package if could be in the catch block of the /sbin/ldconfig spawn and introspect the error and retry with ldconfig from path?

  4. uri-canva commented on Feb 22, 2021

    @uri-canva

    Alternatively an option to entirely disable validating dependencies would work even better: I'm noticing ldconfig is only used to provide an error message suggesting how to install missing dependencies.

  5. aslushnikov commented on Feb 22, 2021

    @aslushnikov
    Contributor

    Uri Baghin (@uri-canva) Joscha Feth (@joscha) Is this the only thing that breaks Playwright on Nix? In this case, would symlinking the right ldconfig to /sbin/ldconfig solve it on your end?

  6. joscha commented on Feb 22, 2021

    @joscha

    A system can have multiple nix profiles. Which one is used is dependent on the environment started. These virtualizations only affect the PATH (and a few other things like env) but not the file system, so changing a symlink is not really idiomatic as you would suddenly bind the static filesystem to a specific, arbitrary nix profile.
    On CI (where we intend to run this) it would mean that the symlink would point to a random profile or possibly nothing at all.
    I understand that an env var driving this might be an API we don't want to introduce but what do you think about falling back from the entry in PATH to the hardcoded location or skipping use of ldconfig altogether like Uri Baghin (@uri-canva) suggested?

  7. aslushnikov commented on Feb 22, 2021

    @aslushnikov
    Contributor

    Joscha Feth (@joscha) if this is the only thing that doesn't work on Nix - then sure, we can come up with something as long as it's non-intrusive for the codebase & API.

    But is this the only thing that prevents you from running on NIX? For example, I'll be surprised if our browser builds launch on NIX. Have you tried running them?

  8. uri-canva commented on Feb 22, 2021

    @uri-canva
  9. aslushnikov commented on Feb 22, 2021

    @aslushnikov
    Contributor

    The browsers require a wrapper around them to launch on nix: https://github.com/ludios/nixos-playwright

    Uri Baghin (@uri-canva) impressive!

    So to double-check: the ldconfig is the last thing that stops you folks from using playwright on nix?

    Would you be open to send a PR that detects *NIX system and disables launch doctor there? I cannot guarantee we land it, but we'll discuss it. I'd appreciate if it's as non-invasive as possible.

    P.S. I apologize for all the questions - I have zero experience with NIX systems, and playing with it in docker was painful - there's even no bash 🤷‍♂️

  10. uri-canva commented on Feb 22, 2021

    @uri-canva

    We can make it agnostic to nix: look if ldconfig is on PATH, if not try /sbin/ldconfig, if that doesn't exist either fail?

  11. aslushnikov commented on Feb 22, 2021

    @aslushnikov
    Contributor

    This sounds good to me!

  12. olebedev commented on Mar 11, 2021

    @olebedev
    Contributor

    I have made a PR that allows disabling host requirements validation, please have a look #5806.

  13. 13 remaining items

  14. pbek commented on Nov 3, 2023

    @pbek

    Currently, this shell.nix is working for me:

    { pkgs ? import <nixpkgs> {} }:
      pkgs.mkShell {
        # nativeBuildInputs is usually what you want -- tools you need to run
        nativeBuildInputs = with pkgs; [
          playwright-driver.browsers
        ];
    
        shellHook = ''
          export PLAYWRIGHT_BROWSERS_PATH=${pkgs.playwright-driver.browsers}
          export PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS=true
        '';
    }
  15. ManUtopiK commented on Jan 22, 2024

    @ManUtopiK

    Patrizio Bekerle (@pbek) It works also for me with node package @playwright/test version 1.40.1 with the same shell.nix.
    I updated to 1.41.1 and now I can't launch playwright : Error No chromium-based browser found on the system.
    I've downgraded for now...

  16. pbek commented on Jan 22, 2024

    @pbek

    I already added the version matching in the nix wiki last week, because I had a similar issue. 😅

  17. ml21 commented on Feb 9, 2024

    @ml21

    Sorry, if my questions are stupid - I'm newbie in nix.

    I already added the version matching in the nix wiki last week, because I had a similar issue. 😅

    I tried to find it in wiki https://nixos.wiki/wiki/Playwright , but no version matching there. Where can I find this version matching?

    And one more question please - in wiki:

    Note: Keep in mind that you need to use the same version of playwright in your node playwright project as in your nixpkgs, or else playwright will try to use browsers versions that aren't installed!
    

    How can I specify playwright\playwright-driver.browsers version in my flake.nix?

    For example, if my project uses playwright version 1.41 how can I specify right playwright\playwright-driver.browsers nixpkgs versions?

    Here is my test flake with dev env

    {
      description = "dev env";
    
      inputs = {
        nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
      };
    
      outputs = { self, nixpkgs }: let
        system = "x86_64-linux";
        pkgs = import nixpkgs { inherit system; };
      in {
          devShells.${system}.default = pkgs.mkShell {
          packages = with pkgs; [
            nodejs
            dotnet-sdk_8
            playwright
          ];
    
          PLAYWRIGHT_NODEJS_PATH = "${pkgs.nodejs}/bin/node";
          PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS = true;
          PLAYWRIGHT_BROWSERS_PATH="${pkgs.playwright-driver.browsers}";
    
          shellHook = ''
            echo "dev env started"
            fish && echo "exit dev env" && exit
          '';
        };
      };
    }
    
  18. pbek commented on Feb 9, 2024

    @pbek

    Note: Keep in mind that you need to use the same version of playwright in your node playwright project as in your nixpkgs, or else playwright will try to use browsers versions that aren't installed!

    I was talking about that note. 😉

    I was looking at https://search.nixos.org/packages?channel=unstable&from=0&size=50&sort=relevance&type=packages&query=playwright-driver, noting the version.
    Then updating my flake.
    Then installing exact that version with npm too.

  19. ml21 commented on Feb 9, 2024

    @ml21

    Then installing exact that version with npm too.

    What if I can't change the version in the project (dotnet in my case, not node)?

    In this case, I need to find and specify a suitable version of playwright from nixpkgs.

    How could I do that?

    —-
    Updated:
    I think I found a way to find old versions: https://www.nixhub.io/packages/playwright

    Anyway - Patrizio Bekerle (@pbek) thank you, your posts here and on discourse very useful for me

  20. pbek commented on Feb 10, 2024

    @pbek

    https://www.nixhub.io/packages/playwright

    Oh, that's nice. I didn't know that service! And I didn't know "devbox". Did you try it, Михаил Любимов (@ml21)? Does it create a flake for your project to pin the version? Because that's what I would have done. Pin the nix version of playwright (by searching the github nixpkgs repository for the commit hash of exactly the version that I need) with a nix flake.

  21. ml21 commented on Feb 12, 2024

    @ml21

    Did you try it, Михаил Любимов (@ml21)?

    Patrizio Bekerle (@pbek) I haven’t tried devbox yet because I want to use as few additional utilities as possible. I simply specify the version (found on nixhub) of the nixpkgs that has the version of playwright I need.

    For example, I need playwright v1.34:

    {
      description = "dev env";
    
      inputs = {
        nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
        nixpkgs-pw-v1_34.url = "github:NixOS/nixpkgs/dfcffbd74fd6f0419370d8240e445252a39f4d10";
      };
    
      outputs = { self, nixpkgs, nixpkgs-pw-v1_34 }: let
        system = "x86_64-linux";
        pkgs = import nixpkgs { inherit system; };
        pkgs-pw-v1_34 = import nixpkgs-pw-v1_34 { inherit system; };
      in {
          devShells.${system}.default = pkgs.mkShell {
          packages = [
            pkgs.nodejs_18
            pkgs.dotnet-sdk_8
            pkgs.process-compose
            pkgs-pw-v1_34.playwright
          ];
    
          PLAYWRIGHT_NODEJS_PATH = "${pkgs.nodejs}/bin/node";
          PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS = true;
          PLAYWRIGHT_BROWSERS_PATH="${pkgs-pw-v1_34.playwright-driver.browsers}";
    
          shellHook = ''
            echo "dev env started"
            fish && echo "exit dev env" && exit
          '';
        };
      };
    }
    
  22. pbek commented on Feb 12, 2024

    @pbek

    Meir (@ml2), yes that's what I would have done too.
    Meanwhile, I tried devbox, works great too to pin the version.

  23. tobiasBora commented on Jun 11, 2024

    @tobiasBora

    So another solution is to use nix-ld that is available by default in nixos using something like this in your configuration.nix:

      # Automatically creates a loader in /lib/* to avoid patching stuff
      # To disable it temporarily use
      # unset NIX_LD
      programs.nix-ld = {
        enable = true;
        libraries = with pkgs; [
          # List by default
          zlib
          zstd
          stdenv.cc.cc
          curl
          openssl
          attr
          libssh
          bzip2
          libxml2
          acl
          libsodium
          util-linux
          xz
          systemd
    
          # My own additions
                xorg.libXcomposite
          xorg.libXtst
          xorg.libXrandr
          xorg.libXext
          xorg.libX11
          xorg.libXfixes
          libGL
          libva
          pipewire
          xorg.libxcb
          xorg.libXdamage
          xorg.libxshmfence
          xorg.libXxf86vm
          libelf
          
          # Required
          glib
          gtk2
          
          # Without these it silently fails
          xorg.libXinerama
          xorg.libXcursor
          xorg.libXrender
          xorg.libXScrnSaver
          xorg.libXi
          xorg.libSM
          xorg.libICE
          gnome2.GConf
          nspr
          nss
          cups
          libcap
          SDL2
          libusb1
          dbus-glib
          ffmpeg
          # Only libraries are needed from those two
          libudev0-shim
    
          # needed to run unity
          gtk3
          icu
          libnotify
          gsettings-desktop-schemas
          # https://github.com/NixOS/nixpkgs/issues/72282
          # https://github.com/NixOS/nixpkgs/blob/2e87260fafdd3d18aa1719246fd704b35e55b0f2/pkgs/applications/misc/joplin-desktop/default.nix#L16
          # log in /home/leo/.config/unity3d/Editor.log
          # it will segfault when opening files if you don’t do:
          # export XDG_DATA_DIRS=/nix/store/0nfsywbk0qml4faa7sk3sdfmbd85b7ra-gsettings-desktop-schemas-43.0/share/gsettings-schemas/gsettings-desktop-schemas-43.0:/nix/store/rkscn1raa3x850zq7jp9q3j5ghcf6zi2-gtk+3-3.24.35/share/gsettings-schemas/gtk+3-3.24.35/:$XDG_DATA_DIRS
          # other issue: (Unity:377230): GLib-GIO-CRITICAL **: 21:09:04.706: g_dbus_proxy_call_sync_internal: assertion 'G_IS_DBUS_PROXY (proxy)' failed
          
          # Verified games requirements
          xorg.libXt
          xorg.libXmu
          libogg
          libvorbis
          SDL
          SDL2_image
          glew110
          libidn
          tbb
          
          # Other things from runtime
          flac
          freeglut
          libjpeg
          libpng
          libpng12
          libsamplerate
          libmikmod
          libtheora
          libtiff
          pixman
          speex
          SDL_image
          SDL_ttf
          SDL_mixer
          SDL2_ttf
          SDL2_mixer
          libappindicator-gtk2
          libdbusmenu-gtk2
          libindicator-gtk2
          libcaca
          libcanberra
          libgcrypt
          libvpx
          librsvg
          xorg.libXft
          libvdpau
          # ...
          # Some more libraries that I needed to run programs
          gnome2.pango
          cairo
          atk
          gdk-pixbuf
          fontconfig
          freetype
          dbus
          alsaLib
          expat
          # Needed for electron
          libdrm
          mesa
          libxkbcommon
          # Needed to run, via virtualenv + pip, matplotlib & tikzplotlib
          stdenv.cc.cc.lib # to provide libstdc++.so.6
          pkgs.gcc-unwrapped.lib # maybe only the first one needed
    
          # needed to run appimages
          fuse # needed for musescore 4.2.1 appimage
          e2fsprogs # needed for musescore 4.2.1 appimage
        ];
      };  
    
    

    and then to run

    $ export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$NIX_LD_LIBRARY_PATH"
    $ npx playwright test --ui  
    

    this allows you to use playwright like in any non-nixos system.

  24. rjpcasalino commented on Jun 21, 2024

    @rjpcasalino

    Tobias Bora (@tobiasBora) you just blew my mind; I get some missing stuff for webkit but not a real issue for me

  25. cristianoliveira commented on Dec 24, 2024

    @cristianoliveira

    For those that ended up here after fighting with this issue, and is running under wayland. Running headless browser under wayland is it's own beast and it was experimental not so long ago and required setting some environment variables, so make sure to upgrade NixOs to the latest version before debugging :)

    Also make sure to use the same @playwright/test version to the playwright-driver.browsers which for version 24.11 is 1.47.0

    On the latest version the solution described here https://nixos.wiki/wiki/Playwright works perfectly fine!

  26. tobiasBora commented on Jul 28, 2025

    @tobiasBora

    Note that if you use nix-ld, you just need to additionally run:

    export LD_LIBRARY_PATH=$NIX_LD_LIBRARY_PATH
    

    since I guess the library uses a custom loader not in /lib (the one patched by nix-ld).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions