0

I am running Flask(0.10.1), Python (2.7), Ubuntu(14.04) and PhantomJS(1.9).

I am using PhantomJS to capture a map image, but it hangs because it is not able to find local and remote resources(a local css file and JQuery from a CDN) that I am sure exist(I am able to get those resources using Firefox, curl and wget without any issue).

By the way I have noticed inexplicable behavior such as when running phantomjs directly from the terminal the capture fails,

phantomjs myscript.js

but as soon as I had strace it succeed.

strace phantomjs myscript.js

But then when I start phantomJS with strace through python subprocess it fails again.

subprocess.call(["/usr/bin/phantomjs", "myscript.js"])

Here is what strace display each time it fails:

select([4], [3], [], [], NULL)

My phantomjs script is simple. I am trying to capture a page and I have added wait time because sometime it allows phantomjs to find the resources(a local css file and JQuery from a CDN).

page.open('http://127.0.0.1:xxxx/get-report-map', function() {
    window.setTimeout(function() {
        page.render('~/github24.png');
        phantom.exit();
    }, 8000);
});

Has anybody faced similar issues and how did you solve it?

Raymond Kalonji
  • 345
  • 3
  • 14
  • Normally, I would say that your code looks fine, but it's kind hard to do that without code. Please register to the `onConsoleMessage`, `onError`, `onResourceError`, `onResourceTimeout` events ([Example](https://gist.github.com/artjomb/4cf43d16ce50d8674fdf)). Maybe there are errors. – Artjom B. Jun 05 '15 at 07:58
  • Are you actually using PhantomJS 1.9.0? If yes, then you probably should update to at least 1.9.8. Is the URL an https url? – Artjom B. Jun 05 '15 at 07:59
  • On 1.9.9, it still hangs. On 1.9.8, the error message is `Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL file://myscript.js. Domains, protocols and ports must match. ` – Raymond Kalonji Jun 05 '15 at 16:54
  • Note that I ran `npm install phantomjs@1.9.9` and it installed succesfully. Now, although package.json says version is 1.9.9 the binary says version is 1.9.7 `bin/phantomjs -v` returns 1.9.7 – Raymond Kalonji Jun 05 '15 at 17:01
  • Yes, the npm package version and PhantomJS version went off the rails after 1.9.7. I think package 1.9.13 contains PhantomJS 1.9.8. The "Unsafe..." lines are no actual errors, but a [small bug](http://stackoverflow.com/questions/26608391/using-phantomjs-to-embed-all-images-of-a-webpage-produces-warnings-but-works). It only means that you're on 1.9.8. – Artjom B. Jun 05 '15 at 17:10

0 Answers0