Playwright: Difference between revisions

Installing browsers for Playwright under NixOS: PLAYWRIGHT_LAUNCH_OPTIONS_EXECUTABLE_PATH don't work
Tags: Mobile edit Mobile web edit
Joshbuker (talk | contribs)
Fix shell.nix example not setting allowUnfree = true, which can cause it to fail in some situations
 
(One intermediate revision by one other user not shown)
Line 8: Line 8:
An example <code>shell.nix</code> that installs [[ Visual Studio Code ]] and Playwright.
An example <code>shell.nix</code> that installs [[ Visual Studio Code ]] and Playwright.


<syntaxHighlight lang=nix>
<syntaxhighlight lang="nix">
{ pkgs ? import <nixpkgs> {} }:
{ pkgs ? import <nixpkgs> { config.allowUnfree = true; } }:
   pkgs.mkShell {
   pkgs.mkShell {
     nativeBuildInputs = with pkgs; [
     nativeBuildInputs = with pkgs; [
Line 23: Line 23:
     '';
     '';
}
}
</syntaxHighlight>
</syntaxhighlight>


{{Note|The version of Playwright in Nixpkgs and your node developer environment (in <code>package[-lock].json</code>) must match. See [https://www.nixhub.io/packages/playwright nixhub] to see if there is a version that matches npm in nixpkgs, if not you can also downgrade npm's version via <code>npm install playwright@nixversion</code>. See also [https://discourse.nixos.org/t/running-playwright-tests/25655 this discussion].}}
{{Note|The version of Playwright in Nixpkgs and your node developer environment (in <code>package[-lock].json</code>) must match. See [https://www.nixhub.io/packages/playwright nixhub] to see if there is a version that matches npm in nixpkgs, if not you can also downgrade npm's version via <code>npm install playwright@nixversion</code>. See also [https://discourse.nixos.org/t/running-playwright-tests/25655 this discussion].}}
Line 51: Line 51:
           export PLAYWRIGHT_BROWSERS_PATH=${pkgs.playwright-driver.browsers}
           export PLAYWRIGHT_BROWSERS_PATH=${pkgs.playwright-driver.browsers}
           export PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS=true;
           export PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS=true;
          export PLAYWRIGHT_NODEJS_PATH=${pkgs.nodejs_latest}/bin/node
          playwright_chromium_revision="$(${pkgs.jq}/bin/jq --raw-output '.browsers[] | select(.name == "chromium").revision' ${pkgs.playwright-driver}/browsers.json)"
          export PLAYWRIGHT_LAUNCH_OPTIONS_EXECUTABLE_PATH=${pkgs.playwright-driver.browsers}/chromium-$playwright_chromium_revision/chrome-linux/chrome
          echo "Using $PLAYWRIGHT_LAUNCH_OPTIONS_EXECUTABLE_PATH"
         '';
         '';
       };
       };