question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Running multiple instances of puppeteer while having both user-data-directory and profile-directory defined

See original GitHub issue

Steps 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:

  1. Execute the first instance of puppeteer with a profile defined.
  2. While the first instance is running, I execute another instance with either the same or new profile.
  3. The second browser pops up with the correct profile, but only opens a new blank page and stops running any additional actions.
  4. 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:closed
  • Created 5 years ago
  • Comments:7

github_iconTop GitHub Comments

9reactions
connorjclarkcommented, Feb 16, 2019

@xerxesj Why did you close this - did you find a solution? I’m coming across the same issue now.

0reactions
rinogocommented, Nov 12, 2020

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…

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found