10

I've tried:

  • node-webshot
  • phantomjs

I could do it locally but I couldn't take screenshots of other websites that are based on angularjs.

Bounty

Be able to take a screenshot of any angularjs app which includes jquery and angular on the page. Every single site here: http://builtwith.angularjs.org/ should look as if I loaded it in my browser.

Must be able to get the screenshot via the terminal so it could be run in a background process like a worker or something.

One random server (or whatever should be able to go to an offsite website and take a screenshot of it.)

It just needs to take an url that will inevitably host an angularjs app and output what you'd expect to see in your browser.

Does not need to be phantomjs or node-webshot.

Update 1

As of last night this is how I'm doing it.

  • node-webkit (nodejs inside of chromium) compiled to linux-32
  • leave open on a random laptop
  • when it detects a screenshot needs to be taken (via firebase temporarily) it opens a iframe with that url
  • waits 10 seconds (reasonable time to load a site/app)
  • uses node-webkit api to screenshot itself

I have some work to do on this solution.

enter image description here

Update 2

This appears to be a potential solution but I've found that most of these solutions require opening a browser and taking the screenshot versus a headless browser like phantomjs.

Update 3

I'm continuing development on a production ready solution for this on github. https://github.com/clouddueling/angular-snapshot

If you take this code and build it with node-webkit.app you will be able to run a screenshot server.

Michael J. Calkins
  • 32,082
  • 15
  • 62
  • 91
  • Is node-webshot a requirement or is any alternative that creates screenshots programmatically a viable solution? – Mattias Åslund Dec 14 '13 at 23:57
  • @MattiasÅslund Preferably I'd be able to take a script and just run it in the background. No crazy languages just need a simple way to solve this problem with javascript. Does not need to be based on phantomjs I just need an easy way to take a screenshot from a terminal (hopefully node or ruby or something common). – Michael J. Calkins Dec 15 '13 at 00:28

5 Answers5

3

Have you tried wkhtmltopdf? It comes with a tool called wkhtmltoimage. It uses QtWebKit (A Qt port of the WebKit rendering engine) to render a web page, and converts the result to PDF or image format of your choice, all done at server side.

Because it uses WebKit, it renders everything (images, css and even javascript) just like a modern browser does. You can fine tune the parameters such as tweaking the JavaScript execution grace period.

In my use case, the results have been very satisfying and are almost identical to what browsers would render.

Here's a list of command options:

Name:
  wkhtmltoimage 0.11.0 rc2

Synopsis:
  wkhtmltoimage [OPTIONS]... <input file> <output file>

Description:
  Converts an HTML page into an image, 

General Options:
      --allow <path>                  Allow the file or files from the specified
                                      folder to be loaded (repeatable)
      --checkbox-checked-svg <path>   Use this SVG file when rendering checked
                                      checkboxes
      --checkbox-svg <path>           Use this SVG file when rendering unchecked
                                      checkboxes
      --cookie <name> <value>         Set an additional cookie (repeatable)
      --cookie-jar <path>             Read and write cookies from and to the
                                      supplied cookie jar file
      --crop-h <int>                  Set height for croping
      --crop-w <int>                  Set width for croping
      --crop-x <int>                  Set x coordinate for croping
      --crop-y <int>                  Set y coordinate for croping
      --custom-header <name> <value>  Set an additional HTTP header (repeatable)
      --custom-header-propagation     Add HTTP headers specified by
                                      --custom-header for each resource request.
      --no-custom-header-propagation  Do not add HTTP headers specified by
                                      --custom-header for each resource request.
      --debug-javascript              Show javascript debugging output
      --no-debug-javascript           Do not show javascript debugging output
                                      (default)
      --encoding <encoding>           Set the default text encoding, for input
  -H, --extended-help                 Display more extensive help, detailing
                                      less common command switches
  -f, --format <format>               Output file format
      --height <int>                  Set screen height (default is calculated
                                      from page content) (default 0)
  -h, --help                          Display help
      --htmldoc                       Output program html help
      --images                        Do load or print images (default)
      --no-images                     Do not load or print images
  -n, --disable-javascript            Do not allow web pages to run javascript
      --enable-javascript             Do allow web pages to run javascript
                                      (default)
      --javascript-delay <msec>       Wait some milliseconds for javascript
                                      finish (default 200)
      --load-error-handling <handler> Specify how to handle pages that fail to
                                      load: abort, ignore or skip (default
                                      abort)
      --disable-local-file-access     Do not allowed conversion of a local file
                                      to read in other local files, unless
                                      explecitily allowed with --allow
      --enable-local-file-access      Allowed conversion of a local file to read
                                      in other local files. (default)
      --manpage                       Output program man page
      --minimum-font-size <int>       Minimum font size
      --password <password>           HTTP Authentication password
      --disable-plugins               Disable installed plugins (default)
      --enable-plugins                Enable installed plugins (plugins will
                                      likely not work)
      --post <name> <value>           Add an additional post field (repeatable)
      --post-file <name> <path>       Post an additional file (repeatable)
  -p, --proxy <proxy>                 Use a proxy
      --quality <int>                 Output image quality (between 0 and 100)
                                      (default 94)
      --radiobutton-checked-svg <path> Use this SVG file when rendering checked
                                      radiobuttons
      --radiobutton-svg <path>        Use this SVG file when rendering unchecked
                                      radiobuttons
      --readme                        Output program readme
      --run-script <js>               Run this additional javascript after the
                                      page is done loading (repeatable)
      --disable-smart-width           Use the specified width even if it is not
                                      large enough for the content
      --enable-smart-width            Extend --width to fit unbreakable content
                                      (default)
      --stop-slow-scripts             Stop slow running javascripts (default)
      --no-stop-slow-scripts          Do not Stop slow running javascripts
      --transparent                   Make the background transparent in pngs
      --user-style-sheet <url>        Specify a user style sheet, to load with
                                      every page
      --username <username>           HTTP Authentication username
  -V, --version                       Output version information an exit
      --width <int>                   Set screen width, note that this is used
                                      only as a guide line. Use
                                      --disable-smart-width to make it strict.
                                      (default 1024)
      --window-status <windowStatus>  Wait until window.status is equal to this
                                      string before rendering page
      --zoom <float>                  Use this zoom factor (default 1)

Specifying A Proxy:
  By default proxy information will be read from the environment variables:
  proxy, all_proxy and http_proxy, proxy options can also by specified with the
  -p switch

  <type> := "http://" | "socks5://"
  <serif> := <username> (":" <password>)? "@"
  <proxy> := "None" | <type>? <sering>? <host> (":" <port>)?

  Here are some examples (In case you are unfamiliar with the BNF):

  http://user:password@myproxyserver:8080
  socks5://myproxyserver
  None

Contact:
  If you experience bugs or want to request new features please visit 
  <http://code.google.com/p/wkhtmltopdf/issues/list>, if you have any problems
  or comments please feel free to contact me: <uuf6429@gmail.com>
Dan7
  • 1,657
  • 1
  • 19
  • 31
  • Would you mind testing this on builtwith.angularjs.org? I've gone through so many installs of so many tools that claim similar things. – Michael J. Calkins Dec 15 '13 at 04:38
  • 1
    Hi, tried a few sites from there. Unfortunately they all gave js errors. I think the JS parser from QtWebKit is not up to standard and not suitable for heavy JS sites. Your best bet I know of is probably something like https://addons.mozilla.org/en-US/firefox/addon/imacros-for-firefox/ combined with https://addons.mozilla.org/en-US/firefox/addon/screengrab-fix-version/ to implement an automatic workflow for taking screenshots. Not sure how feasible, but seeing as most other tools use a form of WebKit and didn't work quite well, using a real browser may be the only option. – Dan7 Dec 16 '13 at 10:34
2

Although not personally tried it myself, I have seen service deployed in production that takes screenshots using Webdriver from Selenium.

  1. Build the selenium Webdriver https://code.google.com/p/selenium/
  2. Use the RESTful API to communicate with the server. There are specific calls where you can issue request to fetch a website, and take a screenshot of the current instance

everything is done in the background, so I think it fits your requirement.

leorex
  • 2,058
  • 1
  • 14
  • 15
2

Use browserstack to test your application in all browsers without having to install each one, including mobile browsers, different phones, tablets, etc.

There is support for Selenium automated testing and screenshots. Local testing is supported, no public URL is needed.

The screenshots API is available for configuring the screenshots you need, Screenshooter is a a tool for generating BrowserStack screenshots from the command line.

There is a trial period for this as it's a commercial product, but it's very well made and worth every penny. You can subscribe for only one month. I have used personally and I highly recommend it.

Angular University
  • 42,341
  • 15
  • 74
  • 81
  • 1
    $20/mo and it looks like it passes! http://www.browserstack.com/screenshots/c9e834e8f8890643256cd166e266a0977335d426 and http://www.browserstack.com/screenshots/cb7d7faff6adaff21ef3e6e03549c221112cf66c – Michael J. Calkins Dec 15 '13 at 17:55
  • AngularJS docs: http://www.browserstack.com/screenshots/be4bd09fbd44c076aa172c89af0a1d7a9a0f796b Anyone have a good site to test on this? It looks like this will be the accepted answer. – Michael J. Calkins Dec 15 '13 at 17:57
  • I'm going to let this run a little longer to see if there is a 'free' answer otherwise you get the bounty. – Michael J. Calkins Dec 15 '13 at 18:18
  • Leading me to http://browsershots.org/ and http://browsershots.org/documentation#HowToCreateANewScreenshotFactory – Michael J. Calkins Dec 15 '13 at 19:47
1

Probably this will help https://bitbucket.org/vodolaz095/site-shooter This is nodejs+phantomjs application to make site screenshots

You need a heroku free tier service to run this.

BTW, you can try this application - https://pageshooter.herokuapp.com i think it can make screenshots of angularjs sites

vodolaz095
  • 6,680
  • 4
  • 27
  • 42
1

Node-Webshot uses PhantomJS which in turn uses QtWebkit which doesn't work with AngularJS.

More info: https://github.com/angular/angular.js/issues/2985

Suggestion. Make sure the PhantomJS you have bundled within Node-Webshot is absolutely the latest version. If not, replace the PhantomJS with the latest version and prey for them to have fixed it by now.

If you have access to the command line options of PhantomJS, you could try a few of them in here: https://github.com/ariya/phantomjs/wiki/API-Reference

The ones particularly riging the bell are:

--ignore-ssl-errors=true

--local-to-remote-url-access=true

--web-security=false

Jani Hyytiäinen
  • 5,293
  • 36
  • 45