我遇到了那个确切的问题。它可以用一点技巧来完成,因为它page.evaluate也可以接受一个字符串。
有几种方法可以做到这一点,但我使用了一个名为 的包装器evaluate,它接受额外的参数来传递给必须在 webkit 端评估的函数。你会像这样使用它:
page.open(url, function() {
  var foo = 42;
  evaluate(page, function(foo) {
    // this code has now has access to foo
    console.log(foo);
  }, foo);
});
这是evaluate()功能:
/*
 * This function wraps WebPage.evaluate, and offers the possibility to pass
 * parameters into the webpage function. The PhantomJS issue is here:
 * 
 *   http://code.google.com/p/phantomjs/issues/detail?id=132
 * 
 * This is from comment #43.
 */
function evaluate(page, func) {
    var args = [].slice.call(arguments, 2);
    var fn = "function() { return (" + func.toString() + ").apply(this, " + JSON.stringify(args) + ");}";
    return page.evaluate(fn);
}