0

I am new to using phantomjs, and I just tried to load and render a page using the example given on the website:

var url='http://www.example.com'
var page = require('webpage').create();
page.open(url, function() {
  page.render('example.png');
  phantom.exit();
});

This takes over one minute to run, as reported by time.

I am running on a modern laptop (Thinkpad X1 Carbon) with a Gigabit Ethernet connection, and loading the same page in Firefox takes under a second.

Any hints for finding the root cause of this, or common possible causes of this?

Update: I tried commenting out page.render but the running time is very similar, so I do not think it's a rendering speed issue.

merlin2011
  • 71,677
  • 44
  • 195
  • 329

1 Answers1

1

Hard to tell where is your bottleneck without any details. Provide a version of phantomjs and platform you're running. Generally, I would try to find where a problem is by perfoming the following steps:

  • Try to run phanomjs without js argument, like bin/phantomjs --version

In my case it is 1.9.1. It should respond right away.

  • Try to simplify your js, e.g. in your case you can remove:

    page.render('example.png');

  • Try to install new version of phantomjs. Or if you have already, try different version.

  • Try to look at HAR output:

    bin/phantomjs examples/netsniff.js http://www.example.com

As a result you will see smth like:

 "entries": [
            {
                "startedDateTime": "2014-03-07T11:18:49.841Z",
                "time": 1013,
                "request": {

So, in my case after phantomjs have been loaded into memory, loading a page took 1013 ms.

If it will about the same for you it will mean, that something going wrong during loading phantomjs itself. You can try to debug phantomjs using strace, if you're on Linux or it's analog for Windows.

strace bin/phantomjs examples/netsniff.js http://www.example.com

Then, see at what system call it stops.

Community
  • 1
  • 1
nefski
  • 691
  • 6
  • 12