I had this exact problem. This can be done with a little trick, because page.evaluate can also accept a string.
There are several ways to do this, but I use a shell called evaluate , which takes additional parameters to go to a function that needs to be evaluated on the website side. You would use it as follows:
page.open(url, function() { var foo = 42; evaluate(page, function(foo) {
And here is the evaluate() function:
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); }
Weston Mar 23 '12 at 11:13 2012-03-23 11:13
source share