Today I tried to inject some javascript logic into remote page using CasperJS with PhantomJS together.
Well, I'm quite surprised because of that:
casper.then(function() {
console.log(this.evaluate(function() {
function myMethod() {
return 'Any thing?!';
}
return myMethod();
}));
console.log(this.evaluate(function() {
return myMethod();
}));
});
I tried many combinations... Like:
casper.evaluate(...)
this.evaluate(...)
casper.page.evaluate(...) <- directly to phantomJS
this.page.evaluate(...) <- as above
First case gives me exactly what I want. But next call to evaluate act as an idiot, which never saw executed code above.
I just want to change variables, functions, and other over remote site js runtime.
Can anybody tell me why this is happening? Greetings.
myMethodis private to an anonymous function (in the first call). How do you expect it to be available in a different anonymous function *(second call)? You should show what you are actually trying to do so we can suggest something else.