playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[Bug]: Running Chrome using `launchOptions` will lose out to `PLAYWRIGHT_BROWSERS_PATH` under Bazel if `npx playwright install` run

Open Aghassi opened this issue 1 year ago • 3 comments
trafficstars

Version

1.41.1

Steps to reproduce

I want to be clear that this situation is highly specific to running playwright in bazel so I understand if it's an edge case. I'm more reporting for public visibility.

When we invoke playwright with rules_js under bazel we pass it CHROMIUM_BIN as an env variable which we use to hydrate launchOptions in the playwright config for chromium. We don't have other browsers yet, so it's just Chrome. We do this to point playwright to the location of chromium on the system because we are downloading the chromium binary on our own through Bazel.

However, if we run npx playwright install and get a folder at /Users/<user>/Library/Caches/ms-playwright. Even under Bazel, playwright will choose this directory OVER the one being passed in by launchOptions. While it is unlikely, it does lead to a non hermetic install and non deterministic behavior.

To fix this, I had to export PLAYWRIGHT_BROWSERS_PATH=0. This is no the entirely correct fix, but it does fix the issue. It forces playwright to look locally for checked in binaries, but those will never be there. This then lets playwright fallback on launchOptions and load fine.

Expected behavior

I would expect that for individual binaries, like launchOptions paths, to be respected over the cache location set by default.

Actual behavior

The cache location wins out

Additional context

No response

Environment

System:
    OS: macOS 14.5
    CPU: (10) arm64 Apple M1 Max
    Memory: 5.57 GB / 64.00 GB
  Binaries:
    Node: 18.18.2 - ~/.nvm/versions/node/v18.18.2/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 9.8.1 - ~/.nvm/versions/node/v18.18.2/bin/npm
    pnpm: 8.6.11 - ~/Library/pnpm/pnpm
  IDEs:
    VSCode: 1.90.2 - /opt/homebrew/bin/code
  Languages:
    Bash: 5.2.15 - /opt/homebrew/bin/bash

Aghassi avatar Jun 27 '24 17:06 Aghassi

What is CHROMIUM_BIN? It is not a part of Playwright or something Playwright supports. You should not call npx playwright install if you are bringing your own browser.

pavelfeldman avatar Jun 27 '24 17:06 pavelfeldman

@pavelfeldman I realized I mispoke in my initial issue. I appologize.

The issue is that passing the following

          launchOptions: {
            executablePath: process.env.CHROMIUM_BIN,
          },

does not take precedence over playwright_browser_path when I expect it would.

I was using this env and type up my issue wrong. Let me adjust the issue name and context

Aghassi avatar Jun 27 '24 18:06 Aghassi

What you say below is:

"At runtime, when launching Chromium, use executable located at <CHROMIUM_BIN>."

launchOptions: {
  executablePath: process.env.CHROMIUM_BIN,
},

does not take precedence over playwright_browser_path when I expect it would.

It does take precedence over PLAYWRIGHT_BROWSERS_PATH - the browser from CHROMIUM_BIN will be launched, regardless of the location of the browser registry.

pavelfeldman avatar Jun 27 '24 19:06 pavelfeldman

Closing as per above, please feel free to open a new issue if this does not cover your use case.

pavelfeldman avatar Jul 01 '24 17:07 pavelfeldman