A
A
Alexander Mekhonoshin2014-05-09 13:46:07
Debian
Alexander Mekhonoshin, 2014-05-09 13:46:07

How to get webkit screenshots from the command line?

You need to run the webkit engine under Debian7 or under Windows7 in order to get a screenshot of the entire page as part of the deployment script.
If under Debian, then preferably without x.
I tried various python scripts and the python package manager pip, which did not help me, because for some reason the packages, like one, did not bring dependencies and did not work.
ps I'm not familiar with python.
I also tried to install some packages with names like webkit2png, webkit2pdf, webkit. However, the presence of X11 in their dependencies scared me.
UPD
Here I found a similar question, the answer to which is PhantomJS.
This solution seems to me more convenient, unlike python-based scripts, because it is for Node.js.
Now I'm looking for how specifically to get a screenshot with it.
UPD
There is a link phantomjs.org/screen-capture.html on the main page of the project :) Now I will try. If someone has already done, I will be glad to advice. UPD Although the result was obtained, its quality wants to leave the best. Currently phantomjs uses Mozilla/5.0 (Unknown; Linux i686) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.7 Safari/534.34 Which seems to be roughly equivalent to the terribly outdated Safari 5, which doesn't support all the new stuff from CSS3, so necessary to me. ps along the way, I found a utility that allows you to run applications that require X11 without these Xs, i.e. on the server (thanks

@
0neS )
_
_ run and try to somehow pull out a screenshot from there.
UPD
The page e-method.blogspot.fr/2010/11/google-chrome-with-xv... describes how to do what I need (it's called headless running).
Now I will try.
Perhaps someone has already done it?
UPD
Nothing happened.
Installed Chromium (the original article suggested google-chrome, but it was not in the repositories), xvfb and imagemagick (to take a screenshot)
[email protected]: ~# apt-get install xvfb imagemagick chromium-browser
Ran

xvfb-run --server-args='-screen 0, 1024x768x24' chromium -start-maximized http://google.com > & /dev/null &
DISPLAY=:99 import -window root myimage.png

in anticipation of the coveted screenshot...
And in the first place I got it
-bash: syntax error near unexpected token `&'
Removed the extra ampersand:
xvfb-run --server-args='-screen 0, 1024x768x24' chromium -start-maximized http://google.com > /dev/null &

AND...
DISPLAY=:99 import -window root myimage.png
No protocol specified
import.im6: unable to open X server `:99' @ error/import.c/ImportImageCommand/368.

All sorts of attempts to get through failed...
strace chromium
showed, among other things
(chromium:8571): Gtk-WARNING **: cannot open display:
) = 56
exit_group(1) = ?
So, :99 fake display, apparently never opened ...
UPD
With the help of this article, I managed to learn how to raise a virtual display and take a screenshot.
And here it was written how to solve the problem of starting chromium as root, which I had: just call it like this chromium --user-data-dir
As a result, there is a screenshot of a correctly rendered page!
But a screenshot of the entire page is required, not just the first screen.
I'll try to solve it by writing a JS script that will scroll through the site and a Bash script that should take screenshots synchronously ...
UPD
Oh yes. For those who also needed this, here are the specific actions and results:
Follow steps 1 and 2 on this article . I installed chromium instead of firefox. I didn't use Flash either.
Now bring up the virtual display: `sudo service xvfb start`
Then start chrome DISPLAY=:5 nohup chromium --user-data-dir -start-maximized google.com &
Finally take a screenshot DISPLAY=:5 import -window root screenshot.png Home
position
199858358c604b9388cc611430d0a1e5.png
Chromium launched
e75e89e8853c4afbb7a5dff7831c0f75.png
Snapshot taken
b7d3e6e4b70c4c889c7e991e2ee969fa.png8533760ae36f4f009c29d6dcb751aca7.png

Answer the question

In order to leave comments, you need to log in

5 answer(s)
I
Ivan, 2014-05-09
@0neS

Have you tried all of these options?
www.binarytides.com/take-webpage-screenshot-from-c...
maxivak.com/take-screenshots-of-websites-from-comm... (first two)

S
Sergey, 2014-05-09
Protko @Fesor

Take PhantomJS and don't worry. There are examples, and from experience this is the most uncluttered and supported solution for such tasks. Next comes wkhtmltopdf/wkhtmltoimage, but it can be buggy and... well, it seems to have worse support. And yes, there are fewer opportunities.

G
GM2mars, 2014-05-28
@GM2mars

Do not tell me, your solution, to which you came (raising the virtual display), how resource-intensive it is and how long it takes?
For example, if I need to get 100 screenshots of a small size (300x300). It is clear that it depends on the sites and the download time; if we take the average values.

A
Alexander Mekhonoshin, 2014-10-14
@a_ex

node-webkitgtk (GitHub: kapouer/node-webkitgtk , License: MIT, npm: webkitgtk)
by Jérémy Lal is a collection of webkitgtk bindings for Node. A product's API can be called in a chain, so you can do something like this:
Summary : Installing this contraption is a big problem.
-------------------------------------------------- -------------------------------------------------- -----------------------
There is also segmentio/nightmare , but although it is convenient and easy to install, it works on top of phantomjs and therefore also uses the extremely old engine version.
Summary : absolutely not usable for taking screenshots (layout floats).
-------------------------------------------------- -------------------------------------------------- -----------------------
So the method outlined at the end of the question remains the most effective. Its cons:
- Long installation procedure
- Snapshot of only the first screen
- In order to prevent the browser from getting into the picture, you need to pass the “kiosk”-mode parameter in a tricky way.

S
Sergey, 2015-06-24
@rooltak

Try the webkit-image-gtk or webkit-image-qt package
They have the webkit-image utility. It takes a full screenshot of the page i.e. throughout the length and width.
The syntax can be found in man webkit-image. Although it is primitive in principle:
webkit-image www.onliner.by > output.png
example of the command3900630eb19948bf8b3eea9a0d4d3fd0.PNG

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question