PhantomJS.rb freezing when trying to screen capture page in my rails application

倖福魔咒の 提交于 2020-01-16 04:10:14

问题


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?


回答1:


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 :)



来源:https://stackoverflow.com/questions/32957020/phantomjs-rb-freezing-when-trying-to-screen-capture-page-in-my-rails-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!