brenden/node-webshot

onConsoleMessage does not display anything

hgezim opened this issue · 0 comments

Here's the sample code.

onConsoleMessage function never gets executed.

var webshot = require('webshot');
var fs = require('fs');
var process = require('process');
var argv = require('yargs').argv
var phantom = require('phantomjs2')

var options = {
	// renderDelay: 1000,
	siteType:'html',
	errorIfJSException: true,
	defaultWhiteBackground: true,
	quality: 10,
	phantomPath: phantom.path,
	errorIfJSException: true,
	captureSelector: '#test1 > .nutritionLabel',
	onConsoleMessage: function(msg, lineNum, sourceId) {
  		console.log('CONSOLE: ' + msg + ' (from line #' + lineNum + ' in "' + sourceId + '")');
	}
};
var htmlFile = fs.readFileSync("nutrifact.html", {encoding: 'utf-8'});

options.onCallback = function(data) {
	if (data && data.secret && (data.secret === 'ghostly')) {
		return 'Accepted.';
	}
	return 'DENIED!';
};

webshot(htmlFile, './webfonts.png', options, function(err) {
	if (err) return console.log(err);
	console.log('OK');
});