user310291
user310291

Reputation: 38180

PhantomJs does not return any status when making an http request in console

I downloaded PhantomJS, launched the exe and typed in console

var page = require('webpage').create();
page.open('http://net.tutsplus.com', function(s){console.log(s);})

I didn't see status "success" returned in console and no error either. Why?

I tried using hello.js it prints "success" but it does not in interactive mode, is this normal?

Upvotes: 1

Views: 158

Answers (1)

Artjom B.
Artjom B.

Reputation: 61892

Don't use interactive mode to open pages. Something prevents PhantomJS from opening pages, so the callback is never called. If you wait a little and try to access page.content it still shows the about:blank content. This is because REPL mode is broken.


Previous answer in case this is used as a script and not in interactive mode:

I believe this is a flush problem. Add a second console.log() to see if the first one appears.

Also, it is always a good idea to close the script at which point the output will be flushed:

page.open('http://net.tutsplus.com', function(s){
    console.log(s);
    phantom.exit();
});

I could reproduce this issue on Raspbian with PhantomJS 2.0.1-dev once. All other invocations had no problem anymore.

Upvotes: 1

Related Questions