3 ms·
I've been using chromium-headless for certain automated tasks, and I've been getting a lot better results than from PhantomJS in terms of correctly rendered res
by sebcat 10y ago
I've been using chromium-headless for certain automated tasks, and I've been getting a lot better results than from PhantomJS in terms of correctly rendered resources, resource consumption and execution speed. If your business depends on rendering engines and you're using PhantomJS, chromium-headless is probably something you want instead.
I build from chromium src, and my code is more or less an extension with its own BUILD.gn with a deps on //headless. Once you've built the initial tree (took a night for me), builds will be really fast.
Most of the interaction with the browser is by the chrome debugging protocol, as with "normal" chromium. Generally speaking, you want to target that, instead of the internal APIs.
There are some tweaks you need to be aware of. Chromium needs a homedir, so you want to configure that. There's state stored between sessions, so if you want process invocations stateless, consider spending some time hacking or run the process in a fresh namespace/chroot/docker/jail/whatever each time. I had to write my own protocol handler and URLRequestJobs because I render pages from archives on disk and that was the easiest way to get that started at the time.
I don't know if vanilla chromium supports it, but I'm pretty sure I've seen a --headless flag somewhere... If not, headless_shell is pretty easy to build following the official build instructions[1]. I'm running on RHEL/Fedora/CentOS. There's also unofficial images on docker hub if you want to go that route.
[1]: https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md https://chromium.googlesource.com/chromium/src/+/lkgr/headle...
- Flenser 10y agoHere's the bug to follow if you want to follow progress (the anchor comment in the url is for when screenshot capturing landed) https://bugs.chromium.org/p/chromium/issues/detail?id=546953#c54 https://bugs.chromium.org/p/chromium/issues/detail?id=546953...
- boundlessdreamz 10y agoWhat about startup time? phantomjs is the only headless browser I have tested which starts up relatively fast.
- sebcat 10y agoCan't test now, but around a few tens of milliseconds for about:blank