Puppeteer can't load extension in headless - google-chrome

I'm trying to load an extension to chrome with puppeteer, works in headless:false, but it doesn't with headless: true. Can it be done?
const browser = await puppeteer.launch({
headless: true,
defaultViewport: null,
executablePath: '//usr//bin//google-chrome',
args: [
'--start-maximized',
`--disable-extensions-except=${pathToExtension}`,
`--load-extension=${pathToExtension}`,
`--window-size=1920,1080`,
]
});

Related

How to limit puppeteer browser memory usage

I've tried both variants and neither of them works.
const browser = await puppeteer.launch({
args: [
'--max_old_space_size=1024',
],
headless: true,
});
and
const browser = await puppeteer.launch({
args: [
'--js-flags="--max_old_space_size=1024"',
],
headless: true,
});
What am I doing wrong?
I am not sure if it gonna work as the max. memory usage that can be set varies between platforms, but about the syntax I am sure you should use dashes instead of underscores in --max-old-space-size if you try to set it via --js-flags:
await puppeteer.launch({ headless: true, args: [ '--js-flags="--max-old-space-size=1024"' ] });

How to test the application in Incognito mode using puppetter?

When ever I tried using the below code, it launches a second window in incognito mode.
const context = await browser.createIncognitoBrowserContext();
const page = await context.newPage();
When I tried the below code, it launches the Incognito mode. But opens the url in regular chrome mode
const browser = await puppeteer.launch({
headless: false,
args: [
"--incognito"
]
});

Puppeteer-extra allow flash support

I need puppeteer (not in headless mode) to open a page and have flash enabled from the get go.
Meaning no manual downloading or clicking to run flash.
So far i've added puppeteer-extra and its flash plugin as was used in a prior question:
Allowing to run Flash on all sites in Puppeteer
My chrome version is 75.0.3770.142 and my puppeteer dependencies are:
* "puppeteer": "^1.19.0",
* "puppeteer-core": "^1.19.0",
* "puppeteer-extra": "^2.1.3",
* "puppeteer-extra-plugin-flash": "^2.1.3",
* "puppeteer-extra-plugin-user-data-dir": "^2.1.2",
* "puppeteer-extra-plugin-user-preferences": "^2.1.2",
import puppeteer from 'puppeteer';
import PuppeteerCore from 'puppeteer-core';
import PuppeteerExtra from 'puppeteer-extra';
import PuppeteerFlash from 'puppeteer-extra-plugin-flash';
PuppeteerExtra.use(PuppeteerFlash());
(async () => {
const browser = await PuppeteerExtra.launch({
headless: false,
executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google\ Chrome',
args: [
'--window-size=800,600',
'--enable-webgl',
'--enable-accelerated-2d-canvas',
],
});
const page = await browser.newPage();
await page.setViewport({ width: 800, height: 600 });
await page.goto('http://ultrasounds.com', { waitUntil: 'networkidle2' });
})();
I expected the above code to open the page, download the necessary flash and run the flash content when done.
As it is though, it does the download but still requires a user to click enable flash to make the content run.
I'm wondering if anyone could please let me know if I'm doing anything wrong in the above code, if I've misunderstood something or otherwise?
if you use the localPath chrome app, you needn't the puppeteer-extra-plugin-flash.
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({
executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
ignoreHTTPSErrors: true,
headless: false,
});
const page = await browser.newPage();
await page.goto('https://v.qq.com/iframe/preview.html?width=500&height=375&auto=0&vid=a30198lw6j2');
const dimensions = await page.evaluate(() => {
return {
src: document.getElementById('tenvideo_video_player_0').getAttribute('src'),
};
});
console.log('Dimensions:', dimensions);
await browser.close();
})();

Puppeteer when running in full (non-headless) is always black on all websites

I just got started with puppeteer, I'm it on full mode to learn how it works and create my tests. It worked fine for the first few runs but then the browser turns to black.
Here is how it looks like:
I reinstalled all npm packages (removed project and cloned it back from git and then installed them again), this time too it worked for a few runs then I got this black page problem.
const createBrowser = async (
email: string,
proxy?: string
): Promise<puppeteer.Browser> => {
const userDataDir = `profiles/${slugify(email)}`;
const browser = await puppeteer.launch({
headless: process.env.NODE_ENV === "dev",
userDataDir,
args: ["--no-sandbox"]
});
return browser;
};
const createPage = async (
browser: puppeteer.Browser
): Promise<puppeteer.Page> => {
const page = await browser.newPage();
await preparePageForTests(page);
return page;
};
Try to set the defaultViewport property with null value.
const browser = await puppeteer.launch({
headless: process.env.NODE_ENV === "dev",
defaultViewport: null,
args: ["--no-sandbox"],
userDataDir
});

puppeteer : launch with no-sandbox and no-headless

I must launch puppeteer with this line:
const browser = await puppeteer.launch({args: ['--no-sandbox']} )
But for debugging, I need launch headless: false
I tested:
const browser = await puppeteer.launch({args: ['--no-sandbox']}
headless: false});
But it doesn't work.
Please help me, thanks.
replace with following code
const browser = await puppeteer.launch({
headless: false,
args: ['--no-sandbox', '--disable-setuid-sandbox']
})