Running multiple instances of puppeteer while having both user-data-directory and profile-directory defined
See original GitHub issueSteps to reproduce
Tell us about your environment:
- Puppeteer version: v1.6.2
- Platform / OS version: MacOS High Sierra 10.13.6
- URLs (if applicable): n/a
- Node.js version: v8.2.1
What steps will reproduce the problem?
Please include code that reproduces the issue.
const puppeteer = require('puppeteer');
// payload.settings.chromeProfile = `default` || `Profile 1`
// payload.settings.chromeDir = `/Users/userName/Library/Application Support/Google/Chrome/`
let appConfig = {
width: 960,
height: 900,
deviceScaleFactor: 1
};
let args = {
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--disable-infobars',
'--window-position=0,0',
'--ignore-certifcate-errors',
'--ignore-certifcate-errors-spki-list'
]
};
let userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36';
args.headless = false;
// assign chrome profile path
// enable sync with account
let specialArgs = [`--profile-directory=${payload.settings.chromeProfile}`, '--enable-sync'];
// ignore default flags
args.ignoreDefaultArgs = [
'--password-store=basic',
'--enable-automation',
'--disable-sync',
'--safebrowsing-disable-auto-update',
'--disable-background-networking'
];
args.args.push(...specialArgs);
args.executablePath = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
args.userDataDir = payload.settings.chromeDir ? payload.settings.chromeDir : null;
(async () => {
try {
const browser = await puppeteer.launch(args);
const page = await browser.newPage();
await page.setViewport(appConfig);
await page.setUserAgent(userAgent);
await page.goto('https://www.google.com/', {
waitUntil: 'networkidle2'
});
// run actions...
} catch (error) {
console.log(error);
await browser.close();
}
}
What is the expected result?
I should be able to launch each new instance of a browser with it’s defined profile intact and have it execute its defined actions without messing up the other browser instances.
What happens instead?
The following ends up happening:
- Execute the first instance of puppeteer with a profile defined.
- While the first instance is running, I execute another instance with either the same or new profile.
- The second browser pops up with the correct profile, but only opens a new blank page and stops running any additional actions.
- Once the new blank page opens on the second browser, the first browser re-runs the actions again.
I’ve tested this without setting any profile-directory path and it works correctly.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7
Top Results From Across the Web
Running multiple instances of puppeteer while having both ...
I should be able to launch each new instance of a browser with it's defined profile intact and have it execute its defined...
Read more >how to use user-data-dir but for multiple puppeteer windows
The error is coming from the fact that you are launching multiple browser instances at the very same time hence the profile directory...
Read more >Chromium Docs - User Data Directory
To determine the user data directory for a running Chrome instance: Navigate to chrome://version; Look for the Profile Path field. This gives the...
Read more >Web Scraping with a Headless Browser: A Puppeteer Tutorial
In this article, Toptal Freelance JavaScript Developer Nick Chikovani shows how easy it is to perform web scraping using a headless browser.
Read more >puppeteer-core - npm
Puppeteer is a Node.js library which provides a high-level API to control Chrome/Chromium over the DevTools Protocol. Puppeteer runs in ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@xerxesj Why did you close this - did you find a solution? I’m coming across the same issue now.
Ditto. Why was this closed? Any ideas from the community? I’m think it might have something to do with using tabs vs. windows. I think we might only be able to actively process the active tab. My code seems to be opening separate tabs which may be part of the problem…