brenden / node-webshot

Easy website screenshots in Node.js
2.12k stars 286 forks source link

onConsoleMessage does not display anything #198

Open hgezim opened 7 years ago

hgezim commented 7 years ago

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');
});