问题
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