playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[Bug]: PLAYWRIGHT_BROWSERS_PATH with chromium.launch()

Open pellea opened this issue 1 year ago • 5 comments

Version

1.48.2

Steps to reproduce

in global-setup.ts, use the browser directly (for authentication purpose for example):

async function globalSetup(config: FullConfig) {
    const browser = await chromium.launch();
    const context = await browser.newContext();
    const page = await context.newPage();

    ...
}

Expected behavior

PLAYWRIGHT_BROWSERS_PATH should not be ignored.

Actual behavior

PLAYWRIGHT_BROWSERS_PATH is ignored completely and the only way around this is to specify the executablePath directly

const browser = await chromium.launch({
    executablePath: './binaries/browsers-linux/chromium-1140/chrome-linux/chrome'
  });

Additional context

PLAYWRIGHT_BROWSERS_PATH is working correctly inside a test with:

test(`...`, async ({ context }) => {
    const page = await context.newPage();

    ...
});

Environment

System:
    OS: Linux 5.15 Ubuntu 22.04.5 LTS 22.04.5 LTS (Jammy Jellyfish)
    CPU: (20) x64 12th Gen Intel(R) Core(TM) i7-12700
    Memory: 9.06 GB / 15.46 GB
    Container: Yes
  Binaries:
    Node: 23.3.0 - ~/.nvm/versions/node/v23.3.0/bin/node
    npm: 10.9.0 - ~/.nvm/versions/node/v23.3.0/bin/npm
  Languages:
    Bash: 5.1.16 - /usr/bin/bash

pellea avatar Nov 29 '24 14:11 pellea

I tried to reproduce but was not able to. How do you set the PLAYWRIGHT_BROWSERS_PATH env var? I did the following:

 PLAYWRIGHT_BROWSERS_PATH=bogus npx playwright test

mxschmitt avatar Nov 29 '24 18:11 mxschmitt

I tried to reproduce but was not able to. How do you set the PLAYWRIGHT_BROWSERS_PATH env var? I did the following:

 PLAYWRIGHT_BROWSERS_PATH=bogus npx playwright test

mxschmitt avatar Nov 29 '24 18:11 mxschmitt

With a .env file (I set also some Prisma env vars, db url, ...).

PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
PLAYWRIGHT_BROWSERS_PATH=./binaries/browsers

...

#PRISMA_QUERY_ENGINE_LIBRARY=./binaries/query_engine-windows.dll.node
#PRISMA_SCHEMA_ENGINE_BINARY=./binaries/schema-engine-windows.exe
PRISMA_QUERY_ENGINE_LIBRARY=./binaries/libquery_engine-debian-openssl-3.0.x.so.node
PRISMA_SCHEMA_ENGINE_BINARY=./binaries/schema-engine-debian-openssl-3.0.x
...

DATABASE_URL=...

and in playwright.config.ts:

dotenv.config({ path: path.resolve(__dirname, ".env") });

export default defineConfig({
  globalSetup: require.resolve("./global-setup"),

   ...
)};

pellea avatar Dec 02 '24 11:12 pellea

I see - I was able to reproduce. The issue is that we read this env when the module gets required rather than when its used. We so far didn't intend this env var to be modified / set during the runtime.

Code pointer: https://github.com/microsoft/playwright/blob/4e33ade28754a8cdc9fbc0302d3dc3a0f3eb05c0/packages/playwright-core/src/server/registry/index.ts#L327

I'll leave it open until we have it further clarified internally on how we want to proceed - a workaround for now would be to set it from the outside before instead of doing it in JS via dotenv.

mxschmitt avatar Dec 02 '24 16:12 mxschmitt

Turns out this was hard to implement with our current setup - we recommend setting the environment variable outside of your process for now. e.g. cross-env or a wrapper script.

mxschmitt avatar Dec 03 '24 18:12 mxschmitt

Why was this issue closed?

Thank you for your contribution to our project. This issue has been closed due to its limited upvotes and recent activity, and insufficient feedback for us to effectively act upon. Our priority is to focus on bugs that reflect higher user engagement and have actionable feedback, to ensure our bug database stays manageable.

Should you feel this closure was in error, please create a new issue and reference this one. We're open to revisiting it given increased support or additional clarity. Your understanding and cooperation are greatly appreciated.

pavelfeldman avatar Sep 04 '25 01:09 pavelfeldman