Take a Screenshot of Any Tweet Using Casper.js

| Comments

While Twitter do offer a way of embedding tweets, there’s no guarantee that this feature will stay in its current form, and equally no guarantee that if the tweet is deleted, the embed will continue to work, which is a potential headache for journalists and bloggers.

With this in mind, I’ve developed a quick solution to the problem, using the fantastic headless browser Phantom.js and Phantom.js utility Casper.js.

Simply put, all the solution does is allow you to take a simple screenshot in png format of any tweet you give the URL for.

To get Phantom.js and Casper.js running, first install phantom.js and then casper.js (I won’t go into the details here).

Next, download the script to your machine by running:


You will then be able to grab a screenshot by running the command:

casperjs tweetshot.js {tweet permalink} {output filename}

Your screenshot will then be saved with the filename you requested (with a .png extension).

And that’s it really! Ideally I’d like to wrap it in a simple Sinatra app, so you don’t have to have any technical knowledge to get a link, but that’s something for another day.

If anyone has any improvements to suggest, or would like to build on this, please let me know. I’d love to hear what you can do with this.