如何在 puppeteer 中使用 chrome 配置文件

How to use chrome profile in puppeteer

我无法在 Puppeteer 中使用特定的配置文件。它总是以新用户身份打开 chrome。

例如:我的 chrome 有 3 个配置文件。以下是我用来在特定配置文件中打开 chrome 的代码:

const browser = await puppeteer.launch({
    headless: false,
    executablePath: 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe',
    // args: ['--profile-directory="Profile 1"'],
    userDataDir:"C:\Users\USER_NAME\AppData\Local\Google\Chrome\User Data\Profile 1"
  });

但它总是以 "Current user" 配置文件打开 chrome。

试试下面的代码:

const browser = await puppeteer.launch({headless:false, args:[
'--user-data-dir=/user/data/directory/profile_n']
});

这里给出了完整的解释: