alexscheelmeyer / node-phantom

bridge to PhantomJS from Node.js
317 stars 117 forks source link

page.evaluate(func, callback, param). param can not be a Function. #67

Open damphat opened 11 years ago

damphat commented 11 years ago

params can be Function in phatomjs, but node-phantom currently does not support it.

function getBodyHTML(){
    return document.body.innerHTML
}

var phantom = require('node-phantom')
phantom.create(function(_, ph){
    ph.createPage(function(_, page){
        page.open('http://example.com', function(_, status){
            console.log(status);
            page.evaluate(function(aFunc) {
                return aFunc()     // FAILED HERE !!!!!!!
            }, function(_, ret){
                console.log(ret)
            }, getBodyHTML)
        })
    })
})

I currently solve the problem by func.toString() then eval. But I would like node-phantom can support function serialize.

Laboratory commented 10 years ago

+1

n-sham commented 8 years ago

+1