I've got a function which works great on a standard browser (ie, firefox, chrome,...) but some part of it doesn't with PhantomJS.
So, I have a file - let name it script1.js - which looks like this :
const CONST1 = 1;
function f1()
{
//...
myVar = (typeof myVar === "undefined") ? CONST1 : myVar;
//...
}
And here is a sample of the script run by PhantomJS:
var page = webPage.create();
page.open(url,function(status){
if (page.injectJs('script1.js')) {
page.evaluate(function(){
//...
f1();
//...
});
}
});
Using PhantomJS, if myVar
is not set, it doesn't takes the value of CONST1
and still undefined. Indeed, CONST1
's value is undefined. If I change for :
myVar = (typeof myVar == "undefined") ? "value" : myVar;
myVar
will be "value".
Is there a way to use constants with PhantomJS?