This project is a tiny proof of concept to make screenshots of websites with nodejs and the QtWebKit webview.
The goal is to be able to make screenshots on a headless server from a rich scriptable environment.
var booh = require('booh');
var browser = new booh.Browser();
browser.load('http://github.com');
browser.on('loadFinished', function () {
browser.screenshot('github.png');
});- Linux only
- Qt5, Qt5WebKit and Qt development utilities (essentially the moc command)
npm install git://github.com/BenoitZugmeyer/booh.git
To ArchLinux users: you may want to prepend PYTHON=python2 to this
command.
All this API is in development and may change at any time.
booh.Browser- The main class. Each browser are independent. It implements the node EventEmitter class.
close()- This will free the underlying view. You have to close all the browsers to stop the node event loop (and gracefully stop the node process).
load(url)- Load a given URL in the browser.
screenshot(outputFile)- Takes a screenshot and store it as a PNG file.
setSize(size)Set the size of the browser. Without argument, the browser will be resized to fit its current content. Else, it should be an object with optional properties width and height describing a size in pixels. Any missing property will be replaced by the current content metric.
Note: the default size is 1024 x 768.
show()- Show the browser. An interactive window will be opened. You can use this to check what's wrong with the website. There is no hide() yet.
setUserAgent(useragent)- Set the user agent.
You can register events with the node events api methods. Each event will have one object as argument.
loadProgressEmitted when a page is being loaded.
event.progressnumber from 0 to 100: the current load statusloadFinishedEmitted when the page is loaded. This does not handle asynchronous assets loading.
event.successboolean: the global success of the page load.requestFinishedAn HTTP request has finished.
event.urlstring: the URL of the responseevent.headersarray: all response headersevent.requestobject: the source requestevent.request.urlstring: the requested URLevent.request.headersarray: all request headers
My C++ and Qt skills are a little rusty. I used this qt-project example as a starting point.
The integration of Qt into nodejs is greatly inspired from node-qt.