1

I'm having trouble getting a screen capture from my application while using the phantomjs.rb gem. I'm currently just trying local url's. If I get those working I'll use url_for's later.

In my controller:

Phantomjs.run('./public/javascripts/testScreenCapture.js', 'http://localhost:3000')

And my testScreenCapture.js:

var page = require('webpage').create();

var args = require('system').args;
var url = args[1];

page.open(url, function () {
    window.setTimeout(function () {
      page.render('./public/appPage.png');
      phantom.exit();
    }, 3000);
});

Passing "http://www.google.com" as the url argument works fine, it's just when I pass anything from my local server is when the rails server hangs and I'm assuming the phantomjs script as well since I'm not getting an screenshot in my public folder.

What's even more odd is running this from command line:

phantomjs public/javascripts/testScreenCapture.js http://localhost:3000

This works great! So I'm assuming it's something wrong with my controller conflicting with the server. Any ideas?

zuff
  • 55
  • 5
  • I think javascript is 0-indexed -- you should be pulling out the args starting at `args[0]` –  Oct 05 '15 at 20:18
  • @bdares Since the script file location itself is the first argument, there's no reason to call [0]. I'm wanting the next three arguments for my script which is the email, password, and URL. – zuff Oct 05 '15 at 20:27
  • http://phantomjs.org/api/webpage/method/open.html shows how to look at the request status. I'd suggest starting with that to see if the HTTP request itself is working fine. –  Oct 05 '15 at 20:45
  • @bdares any idea how I can access the log if this script is running from rails? Running phantomjs from the command line provides console logs but from my controller I've yet to find a log. – zuff Oct 05 '15 at 21:01
  • @bdares so I've simplified my testing methods. Check the OP for details – zuff Oct 05 '15 at 21:14

1 Answers1

2

You have to use a multi-threaded web server like puma.

See here for an overview of different options.

Another pitfall might be your controller logic. If the page, that gets rendered by phantom, triggers the same controller action than the one, that calls phantom, you create an infinite loop.

Then, even a multi-threaded server would get stuck :)

Community
  • 1
  • 1
thutt
  • 640
  • 5
  • 18