最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Headless ChromePuppeteer window-size vs setViewport - Stack Overflow

programmeradmin1浏览0评论

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 puters resolution ...

Many thanks.

NH

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 puters resolution ...

Many thanks.

NH

Share Improve this question edited May 11, 2020 at 17:47 hardkoded 21.7k3 gold badges61 silver badges74 bronze badges asked Nov 13, 2019 at 0:37 Nicholas HamiltonNicholas Hamilton 10.5k7 gold badges62 silver badges90 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

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.

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.

发布评论

评论列表(0)

  1. 暂无评论