5

I have 100 web pages that I have to test for runtime errors. I found the Puppeteer plugin that can do that "no sweat", but I ran into one dilemma: have one launched browser with multiple tabs or new browser for each link. What is the best approach in this case?

In case of multiple tabs, I heard, there is a chance that css animation and something else (can't remember now) would not work when tab is not in focus.

Multiple browser, obviously, causes the higher CPU load (no?)

Marlone G.
  • 79
  • 1
  • 4
  • 1
    Possible duplicate of [Managing puppeteer for memory and performance](https://stackoverflow.com/questions/51971760/managing-puppeteer-for-memory-and-performance) – Grant Miller Sep 07 '18 at 19:14

1 Answers1

9

These are the advantages of each method in my opinion:

Advantage of multiple browsers:

  • Separate processes: If one browser crashes, the other browsers keep running

Advantage of one browser (with multiple pages):

  • Less memory usage: Although in reality memory and CPU usage depends to a high degree on the task you are doing (screenshot, DOM manipulation)
  • The cookies (and other data) are shared

There is also the option to use multiple contexts, which needs less memory than two separate browsers, but does not share cookies.

So in reality, you should probably just give both options a try. You might want to have a look at the library puppteer-cluster I wrote, which also takes care of error handling and browser restarting in case of crashes.

You can just write your code and switch between multiple browsers vs multiple pages with just one line:

const cluster = await Cluster.launch({
    concurrency: Cluster.CONCURRENCY_PAGE, // which kind of concurrency
    maxConcurrency: 2, // number of parallel workers
});

Just replace CONCURRENCY_PAGE with CONCURRENCY_BROWSER to give multiple browser a try. There is also a third option CONCURRENCY_CONTEXT you might want to try.

Thomas Dondorf
  • 23,416
  • 6
  • 84
  • 105
  • It's mostly animated stuff (css and js animation). What I'm afraid of is that css animation will not start playing until the tab is not in focus, which is the common thing for browsers... – Marlone G. Sep 09 '18 at 00:42
  • Go with the browser option then and you are probably fine. Just give it a try and if it's not working, show me your code and I'll take a look. – Thomas Dondorf Sep 09 '18 at 19:15