Hey everyone,
I’ve been struggling with Playwright and finally got my tests to work in headless mode. I fixed the ‘browserType.launch: spawn UNKNOWN’ error by setting the executablePath in launchOptions.
But now I’m facing a new issue. When I try to run the tests in headed mode using the --ui flag, it’s not working. The browser doesn’t open and I can’t see what’s happening.
Has anyone else run into this problem? Any ideas on how to get the headed mode working? I’ve tried updating Playwright and my browser, but no luck so far.
Here’s a simplified version of my setup:
const browser = await chromium.launch({
headless: false,
executablePath: '/path/to/chrome'
});
const page = await browser.newPage();
await page.goto('https://example.com');
// More test code here
Any tips or suggestions would be really appreciated. Thanks!
I’ve dealt with this exact problem before, and it can be pretty frustrating. One thing that worked for me was clearing the browser cache and user data before launching. You can do this by adding the userDataDir
option to your launch configuration:
const browser = await chromium.launch({
headless: false,
executablePath: '/path/to/chrome',
args: ['--no-sandbox', '--disable-setuid-sandbox'],
userDataDir: './temp-user-data'
});
This creates a fresh user profile for each test run, which can help bypass any weird caching issues.
Another thing to check is your system’s firewall or antivirus software. Sometimes they can interfere with Playwright in headed mode. Try temporarily disabling them to see if that’s the culprit.
Lastly, if you’re on Windows, make sure you’re running your tests with administrator privileges. I’ve seen cases where headed mode wouldn’t work without elevated permissions.
Hope this helps! Let us know if you manage to get it working.
hey mate, i had this issue too. try adding ‘–disable-gpu’ to ur launch args. like this:
const browser = await chromium.launch({
headless: false,
executablePath: ‘/path/to/chrome’,
args: [‘–disable-gpu’]
});
this fixed it for me. if that dont work, maybe check ur graphics drivers r up to date. good luck!
I’ve encountered similar issues with Playwright in headed mode. One thing that often helps is explicitly setting the channel when launching the browser. Try modifying your launch options like this:
const browser = await chromium.launch({
headless: false,
channel: 'chrome',
executablePath: '/path/to/chrome'
});
Also, make sure you’re not running into any permission issues. Sometimes, headed mode requires additional system permissions that headless doesn’t. If you’re on macOS, check if you’ve granted the necessary permissions to your terminal or IDE.
If those don’t work, you might want to try running Playwright with increased logging. Add the PWDEBUG=1 environment variable when running your tests. This can provide more insight into what’s happening behind the scenes.