set a limit on pages number per browser
See original GitHub issueHi,
Tell us about your environment:
- Puppeteer version: 1.11.0
- Platform / OS version: Centos 7
- URLs (if applicable):
- Node.js version: v10.14.2
Is there a way to en n pages in a browser and limit the page number by a maxNbrePage parameter.
I have a long list of url to open, and I would like to open them but with maximum of 3 pages at the same time. and repace finished or loaded page by a new page in the list.
I tested with this code, it works, but without a limit on the pages number at time.
'use strict';
const puppeteer = require('puppeteer');
async function processPage(browser, url) {
console.log("processPage start:", url);
const page = await browser.newPage();
const response = await page.goto(url, {
timeout: 3000000
});
await page.close();
console.log("processPage end:", url);
return {page:response};
}
(async function main() {
try {
const browser = await puppeteer.launch({
headless: true,
args: ['--no-sandbox'],
userDataDir: `${__dirname}/profile-dir`
});
var requests = ['http://example.org/', 'https://www.example.com/', 'http://www.example.com/', 'http://www.example.org/','http://www.example.org/', 'http://www.example.com/', 'http://www.example.com/', 'http://www.example.org/'];
var response_promises = [];
requests.forEach(function(request) {
response_promises.push(processPage(browser, request));
});
var responses = await Promise.all(response_promises);
await browser.close();
} catch (err) {
console.error(err);
}
})();
Thanks
Issue Analytics
- State:
- Created 5 years ago
- Comments:6
Top Results From Across the Web
Limit - Set Limits for Distracting Sites
To use Limit, simply enter the websites you find distracting and choose a daily time limit. For example, you could limit yourself to...
Read more >How to use Limit | Freedom Help Center
Using Limit To use Limit, simply click on the icon, which is usually located at the top right of your browser window. Then...
Read more >Browser limitation with maximum Page length - Stack Overflow
I googled and found that the limit of a web page should be 10-30KB but in the same project we have pages with...
Read more >Blocking: The Web Performance Villain - The Blue Triangle Blog
So depending on what browser is used, the limit on the number of connections per host will range anywhere from 2 to 13,...
Read more >Set time limits for apps and websites in Screen Time on Mac
Limit a website: Click the arrow next to the Websites category at the bottom of the list. If the website has been visited,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
‘use strict’;
const puppeteer = require(‘puppeteer’);
async function processPage(browser, url) { console.log(“processPage start:”, url); const page = await browser.newPage(); const response = await page.goto(url, { timeout: 3000000 }); await page.close(); console.log(“processPage end:”, url); return {page:response}; }
(async function main() {
try { const browser = await puppeteer.launch({ headless: true, args: [‘–no-sandbox’], userDataDir:
${__dirname}/profile-dir
});} catch (err) { console.error(err); } })();
If it helps anyone, you can use the example from the accepted answer in the following StackOverflow post to limit the number of pages per browser: https://stackoverflow.com/questions/50557418/puppeteer-opening-chrome-instance-for-each-file-at-once