Puppeteer: The browser is already running for {value}. Use a different `userDataDir` or stop the running browser first.
The requested userDataDir is already used by a running browser.
The requested userDataDir is already used by a running browser.
Error message
The browser is already running for {value}. Use a different `userDataDir` or stop the running browser first.
{value} is replaced by the value shown in your error message.
How this error happens
Two launched browsers cannot both own the same profile directory. Launching the second while the first is still running conflicts with the profile lock.
The snippets use the imported puppeteer instance.
const firstBrowser = await puppeteer.launch({
userDataDir: "/absolute/path/automation-profile",
});
await puppeteer.launch({
userDataDir: "/absolute/path/automation-profile",
});
How to fix
Let each independent browser use its own temporary profile, or reuse the first browser for multiple isolated contexts.
const firstBrowser = await puppeteer.launch();
const secondBrowser = await puppeteer.launch();
try {
const firstContext = await firstBrowser.createBrowserContext();
const secondContext = await secondBrowser.createBrowserContext();
await firstContext.close();
await secondContext.close();
} finally {
await firstBrowser.close();
await secondBrowser.close();
}
Things to keep in mind
Do not delete profile lock files while their browser is running. Stop the process you own or choose a different directory.