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"' ] });
Related
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`,
]
});
Is it possible to close all running puppeteer browsers using some block of code?
I have opened more browsers using for loop and I want to stop them before exiting the process using process.exit().
I would like to to clear temporary files of the browsers (cached and others), I am starting browsers using
const browser = await puppeteer.launch({ headless: true, args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-features=site-per-process', '--proxy-server=proxy_url'] });.
You can the method close(), see https://pptr.dev/#?product=Puppeteer&version=v12.0.1&show=api-browserclose
Single browser:
const browser = await puppeteer.launch({ headless: true, args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-features=site-per-process', '--proxy-server=proxy_url'] });
// ... DO STUFF ...
await browser.close();
Multiple browsers:
const browserOptions = { headless: true, args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-features=site-per-process', '--proxy-server=proxy_url'] };
const maxBrowsers = 3;
const allBrowsers = [];
for(let i = 0; i < maxBrowsers; ++i) {
const aBrowser = await puppeteer.launch(browserOptions);
allBrowsers.push(aBrowser);
}
// ... DO STUFF ...
// close browsers one by one
for(let aBrowser of allBrowsers) {
await aBrowser.close();
}
// or close browsers all at once
// await Promise.all(
// allBrowsers.map(aBrowser => aBrowser.close())
// );
Even though most of the process of my end-to-end test with puppeteer works fine ( which is a rather simply a series of page.select/type/waitfor/etc) the UI seems skewed.
When the process is over, at the very end of it the UI readjusts to what it should look like but only after everything has concluded. I tried firing up a plain Chromium instance and it looks as it should be as well.
test code looks like so
beforeAll(async () => {
browser = await puppeteer.launch(
{
headless: false,
slowMo: 250,
}
)
page = await browser.newPage()
await page.goto('http://localhost:3000/');
})
describe('on page load', () => {
test('MessageLists loads', async () => {
await page.waitForSelector('.MessageList', { timeout: 3000 })
await page.waitForSelector('.messageOuterContainer', { timeout: 10000 })
},
16000
);
test('Post Question', async () => {
await page.waitForSelector('.messageOuterContainer', { timeout: 10000 })
await page.focus('.input');
await page.keyboard.type('test');
await page.$('.AnswerList');
await page.screenshot({ path: 'screenshot1.png' });
}, 20000)
})
afterAll(() => {
// browser.close()
})
Im on MacOS Mojave 10.14 though i imagine this isnt the culprit here.
Even if you launch puppeteer in headless: false mode, the page will be run with a given viewport. By default that viewport size is 800x600. If you resize the window to something bigger it might indeed look like the page is run inside an iframe. You cannot resize the viewport by resizing the browser window. You have to rely on functions for that.
Code sample
To change the default viewport, you can add an argument when calling puppeteer.launch:
const browser = await puppeteer.launch({
defaultViewport: { // example: 1600x800
width: 1600,
height: 800
},
headless: false,
slowMo: 250,
})
You can also change it by calling the function page.setViewport.
I bought a proxy server version of socsk5.
In all manuals the same example
const browser = await puppeteer.launch({
headless: true,
ignoreHTTPSErrors: true,
defaultViewport: {...winSize},
args: [
'--proxy-server=socks5://proxyhost:8000',
'--host-resolver-rules="MAP * ~NOTFOUND , EXCLUDE proxyhost"',
],
})
It does not specify a login password for this proxy and it clearly does not work
If you specify this
'--proxy-server=socks5://user:password#proxyhost:8000',
it gives an error
net::ERR_NO_SUPPORTED_PROXIES
I tried with https://github.com/sjitech/proxy-login-automator build a bridge, but it did not work either.
Prompt please
You can use page.authenticate() to provide the credentials for your proxy.
For example:
'use strict';
const puppeteer = require('puppeteer');
(async () => {
const username = 'johndoe';
const password = 'qwerty1';
const browser = await puppeteer.launch({
args: [
'--proxy-server=socks5://proxyhost:8000',
],
});
const page = await browser.newPage();
await page.authenticate({
username,
password,
});
await page.goto('https://www.example.com/');
await browser.close();
})();
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']
})