My requirement is to test chrome extensions on a new profile.
I referred https://peter.sh/experiments/chromium-command-line-switches/ for Chromium args[--user-data-dir, --profile-directory]
After the browser is launched, 2 chrome windows are opened. One with given profile and extension and another with default profile and given extension. Also the focus is on a window with default profile. So all actions are happening on it.
I had expected that only 1 browser window would be opened with desired profile and extension.
I tried to switch focus to desired window but browser.BrowserContexts().length is 1, which is browser with default profile. Also browser.targets() shows that there is only 1 target with type as browser.
My Environment:
1. Puppeteer version: 6.9.0
2. Platform / OS version: Windows 10 Pro version 1803
3. URLs (if applicable):
4. Node.js version: 10.16.3
What I tried:
a. Open chrome.exe from path\to\my\project\node_modules\puppeteer.local-chromium\win64-674921\chrome-win\chrome.exe
b. Click on profile icon and open Manage People dialog.
c. Add new person (Profile)
d. Open chrome://version and make a note of Profile Path and close the browser.
e. Create example1.js, example2.js and execute it using node example1.js, node example2.js. The code for both examples are given below.
example1.js
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({headless:false, args:['--disable-extensions-except=\\path\\to\\my\\extension',
'--load-extension=\\path\\to\\my\\extension',
'--user-data-dir=%userprofile%\\AppData\\Local\\Chromium\\User Data',
'--profile-directory=Profile 1'
]});
const page = await browser.newPage();
await page.waitFor(5000);
await browser.close();
})();
example2.js
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({headless:false, args:['--disable-extensions-except=c:\\dev\\prj\\vpnteam\\global VPN\\extension',
'--load-extension=c:\\dev\\prj\\vpnteam\\global VPN\\extension',
'--user-data-dir=c:\\Users\\govinda.s\\AppData\\Local\\Chromium\\User Data',
'--profile-directory=Profile 1'
]});
console.log(browser.browserContexts().length);
var x = await browser.targets();
for(let i=0;i<x.length;i++)
{
if(x[i].type()==='browser')
{
console.log(x[i]['_targetInfo']['targetId']);
}
}
await browser.close();
})();
I had expected Puppeteer should launch Chrome with given:
a. Profile
b. Given extension should be loaded for that profile.
However, apart from above expectations,
a. A browser with default profile is also launched. In total 2 browser windows are opened.
b. The browser with default profile also has given extension loaded.
c. By default, the browser with default profile has focus.
d. browser.browserContexts().length is 1
e. There is only 1 target with type browser