[BUG] VS Code extension: `playwright.env` is not applied to config file
[BUG] using a different .env file with the Playwright for VSCode extension
[FEATURE REQUEST] Allow setting up env variables inside VSCode extensions
[Bug]: VS Code extension no longer picking up .env variables.
Videos
You can put require('dotenv').config() inside your playwright.config.ts and then it will work, see here:
https://www.npmjs.com/package/dotenv
In addition to Max Schmitt's answer, here's 3 other ways to do it:
dotenv-cli
Add dotenv-cli to your dev dependencies then use it: dotenv playwright test (or npx dotenv playwright test if you're running this command outside of a package.json script).
require + NODE_OPTIONS
Use the --require Node.js option and NODE_OPTIONS to set it: NODE_OPTIONS=--require=dotenv/config playwright test.
require + npx
Use the --require Node.js option and npx to set it: npx --node-options=--require=dotenv/config playwright test (if you're using an old version of npx, you might need to replace --node-options by --node-arg)
Not sure exactly if by "browser to show up" you refer at the fact that you need the browser to not run in headless mode.
There are two possible ways:
- Install Playwright Test for VSCode as suggest by @MingJie-MSFT. You'll have a Show browser checkbox there in case you want to run your tests headless or not
- In the config file, for use, add:
headless: false
Example for both options
Please install Playwright Test for VSCode extension which automatically detects if you have Playwright installed and loads the browsers.

Hi all.
I am posting on behalf of one of my QA people who does not have a Reddit account.
We are new to using Playwright and have been struggling with something for a bit now. I fully realize that it is likely something obvious that we missed somewhere along the way.
Essentially, the env and playwright.config.ts files are being run a single time and subsequent runs are running the "cached" version. We noticed this because as part of the config is creating a directory with a timestamp so that we can keep multiple runs separate from each other. We also know that the env is being cached because if we change our secrets in it, it does not pick them up unless we quit VSCode and restart it.
For example, our reporter config looks like this:
reporter: [['list'],['html', { outputFolder: 'Reports/' + (new Date()).toString().replace(/[-:]/g, '_') }]], This should create a new folder on every run. Instead, it remembers the folder from the first run.
Any tips or URLs that could help him, and by expansion the whole team, would be fantastic.