Phantom js access root level functions inside page.evaluate method.

30 views
Skip to first unread message

Pavan Tiwari

unread,
Aug 27, 2017, 1:29:11 PM8/27/17
to phantomjs
Hi All,

I have two JS functions define in common.js file

function test() {};

var obj= new Object();
obj.test=function(){};


I am trying use first test function inside evaluate function definition.

page.open('http://abc.com', function(status) {

  var title = page.evaluate(function() {
console.log(test);
    return document.title;
  });

  console.log(title);
  phantom.exit();

});

Phantomjs fails with exception that test is undefined.
But if i use test through obj Object then i am able to access it.
Could anyone explain me what actually happening behind the seen.

Reply all
Reply to author
Forward
0 new messages