Hacker News new | comments | show | ask | jobs | submit login

What are the pros and cons of running headless Chrome compared to running Chrome in a virtual display driver like Xvfb?



I haven't looked at Headless closely enough yet, but the biggest pros I can see are:

- Potentially less overhead (system resources) - Much simpler setup (compared to something like Xvfb) - Better support for actual automation tasks, e.g. screenshots, separate sessions, etc.

The last point is especially relevant if you run a tool that is visiting many sites in parallel. If you run multiple tabs per process to keep memory usage and Xvfb instances limited then you won't be able to have separate browsing sessions, e.g. two concurrent navigations to the same origin could interfere with each other (cookies, local storage, etc). Another obstacle I have discovered is that you can only take screenshots for the tab that is currently active. For my site (https://urlscan.io) I work around that by manually activating the tab when the load event fires to take the screenshot. Works reasonably well, but can sometimes fail under load.


>If you run multiple tabs per process to keep memory usage and Xvfb instances limited then you won't be able to have separate browsing sessions, e.g. two concurrent navigations to the same origin could interfere with each other (cookies, local storage, etc). Another obstacle I have discovered is that you can only take screenshots for the tab that is currently active.

This is a huge flaw in NightmareJS, which is disappointing because of how beautifully simple its API is. A Nightmare fork rebuilt over headless Chrome would be the best of all worlds for browser automation.


> If you run multiple tabs per process to keep memory usage and Xvfb instances limited then you won't be able to have separate browsing sessions, e.g. two concurrent navigations to the same origin could interfere with each other (cookies, local storage, etc).

Assuming you're running Selenium, this is handled. If you need, you can call each session with its own profile.


Xvfb is way harder to setup. Also, I assume it uses less ressources so it scales better.


I use xvfb-run on Debian and it's a breeze:

    xvfb-run -s '-screen 0 1280x1024x8' ./cucumber
Or are you using more advanced Xvfb features, or perhaps running inside containers?



Yes, I assume that the drawing process may be different. However, it's probably still possible to take a screenshot.

I would like to know what sort of performance differential I can expect.


Screenshot functionality is, in fact, advertised in the linked article.


xvfb can be a bit tough to setup, but Selenium's Docker images make this a breeze, and they even have a debug mode with automatic VNC.


It would be difficult to run this set up on Windows for example.




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact

Search: