Headless Chrome / Puppeteer window-size vs setViewport

5.9k views Asked by At

Doing some web crawling.

Can someone please explain to me, what the difference is, if any, between:

  1. Using the window-size argument when the headless chrome is instantiated:

--window-size=${width},${height}

vs

  1. Setting the viewport

page.setViewport({width,height});

--

I want to know whether there is any advantage to using the 1st method, over the second.

For example, in the eyes of the host, if I use a semi random width/height (ie select from a list of plausible values), will the first offer me any entropic advantage in the same way as selecting a random user agent does?

The second method, 'setViewport' method, is that simply a client side thing for rendering the actual page in the event that one wants to get a screenshot?, or, does it also notify/provide sufficient information to the host as to the nature of my virtual computers resolution ...

Many thanks.

NH

1

There are 1 answers

0
hardkoded On

You could consider --window-size=${width},${height} as the initial viewport.

The good thing about setViewport is that you can change the viewPort many times. It also overrides the window size. For instance, in this image, you can see that the viewport is set to 800x800 and it won't change no matter the size of the window.

enter image description here

I think setViewport will give you more flexibility, and I would consider more stable , because it guarantees that the value you set will be honored.