Playwright: Difference between revisions

imported>Voidless
Created page with "== Installing browsers for playwright under NixOS == Normally at first run, playwright will tell you to run <code>playwright install</code>. The purpose of this is to install..."
 
imported>Voidless
No edit summary
Line 3: Line 3:
<syntaxHighlight lang=nix>
<syntaxHighlight lang=nix>
export PLAYWRIGHT_BROWSERS_PATH=/path/to/drivers
export PLAYWRIGHT_BROWSERS_PATH=/path/to/drivers
</syntaxHighlight>
=== Python example ===
The following flake may be used with <code>nix develop</code> to develop your playwright script:
<syntaxHighlight lang=nix>
{
  description = "Python shell flake";
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    flake-utils.url = "github:numtide/flake-utils";
    mach-nix.url = "github:davhau/mach-nix";
  };
  outputs = { self, nixpkgs, mach-nix, flake-utils, ... }:
    let
      pythonVersion = "python39";
    in
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = nixpkgs.legacyPackages.${system};
        mach = mach-nix.lib.${system};
        pythonEnv = mach.mkPython {
          python = pythonVersion;
          requirements = ''
            playwright
          '';
        };
      in
      {
        devShells.default = pkgs.mkShellNoCC {
          packages = [ pythonEnv ];
          shellHook = ''
            export PYTHONPATH="${pythonEnv}/bin/python"
            export PLAYWRIGHT_BROWSERS_PATH="${pkgs.playwright-driver.browsers}";
          '';
        };
      }
    );
}
</syntaxHighlight>
</syntaxHighlight>