Node.js 运行Phantomjs+有问题;Heroku上的节点
我已经成功地让Phantomjs在Heroku上工作,但现在我遇到了node.js的Phantomjs节点接口的问题(请参阅) 当我试图初始化幻影时,我看到10-15秒的延迟,然后:Node.js 运行Phantomjs+有问题;Heroku上的节点,node.js,heroku,phantomjs,Node.js,Heroku,Phantomjs,我已经成功地让Phantomjs在Heroku上工作,但现在我遇到了node.js的Phantomjs节点接口的问题(请参阅) 当我试图初始化幻影时,我看到10-15秒的延迟,然后: > phantom stdout: ReferenceError: Can't find variable: socket phantom stdout: phantomjs://webpage.evaluate():1 phantomjs://webpage.evaluate():1 phan
> phantom stdout: ReferenceError: Can't find variable: socket
phantom stdout: phantomjs://webpage.evaluate():1
phantomjs://webpage.evaluate():1
phantomjs://webpage.evaluate():1
您可以通过以下步骤或通过在下拉我的测试应用程序重现问题
测试你的应用程序是否启动,第三行到最后一行将告诉你URL,它应该是这样的:
http://fathomless-ravine-5563.herokuapp.com deployed to Heroku
如果成功的话,你应该看看Hello World!在浏览器中
现在,从与Heroku应用程序运行相同的文件夹:
heroku run node
在节点提示下,尝试以下操作:
phantom = require('phantom');
x = phantom.create();
等待10-15秒,您应该会看到错误。从这一点起,一切都不起作用
这应该输出文件foo.png
:
x = phantom.create(function(ph){ph.createPage(function(page){ page.open('http://bbcnews.com', function(status){ page.render('foo.png', function(result) {ph.exit()}); }); }); });
要验证Phantomjs在Heroku上是否正常工作,请使用我的测试项目尝试以下操作:
>heroku run bash
Running `bash` attached to terminal... up, run.1
~ $ phantomjs test.js http://bbcnews.com foo.png
~ $ ls *.png
foo.png
我无法在本地重现任何这些问题,但有其他问题报告,人们可能在本地碰到了这个问题
问题似乎起源于shim.js
第1637行:
s.on('request', function(req) {
var evil;
evil = "function(){socket.emit('message', " + (JSON.stringify(JSON.stringify(req))) + " + '\\n');}";
return controlPage.evaluate(evil);
});
我尝试过node、phantom等版本的变体,但没有成功
我还尝试了一个定制的buildpack,它设置了DYLD变量,看,也没有运气
任何在Heroku上玩得很好的幻影+节点的人请告诉我。在Stackoverflow上有几处提到了这一点,但没有人说“我让它工作起来了,就是这样的”。Heroku不支持WebSocket。对于Socket.io,它有一个。不确定
dnode
,它是phantomjs节点
使用的
我在Heroku上也遇到了WebSocket的问题,我切换到了,这为我解决了问题。我从未使用过phantomjs节点模块,但我确实有一个应用程序在Heroku上同时运行node和phantomjs 您需要使用自定义构建包才能使其正常工作。我的眼睛看起来像
http://github.com/heroku/heroku-buildpack-nodejs.git
http://github.com/stomita/heroku-buildpack-phantomjs.git
然后,您应该能够在子进程中运行phantomjs脚本:
var script = app.get('root') + '/scripts/rasterize.js' //the phantomjs script to run
, bin = app.get('phantom') //normally this would just be the string "phantomjs"
, spawn = require('child_process').spawn;
// set up args to the phantom cli
// (run the phantomjs command in your terminal to see options/format)
var args = [];
// ...
var phntm = spawn(bin, args);
phntm.stdout.on('data', function (data) { /* do something */ });
phntm.stderr.on('data', function (data) { /* do something */ });
phntm.on('exit', function (code) { /* handle exit */ });
你有没有找到答案?我还试图让phantomjs和nodejs在heroku上玩得很好:你有为heroku编译的phantomjs吗?heroku似乎向phantom.js应用推荐这个构建包:-它也比on you参考更新得更多。你试过了吗?
var script = app.get('root') + '/scripts/rasterize.js' //the phantomjs script to run
, bin = app.get('phantom') //normally this would just be the string "phantomjs"
, spawn = require('child_process').spawn;
// set up args to the phantom cli
// (run the phantomjs command in your terminal to see options/format)
var args = [];
// ...
var phntm = spawn(bin, args);
phntm.stdout.on('data', function (data) { /* do something */ });
phntm.stderr.on('data', function (data) { /* do something */ });
phntm.on('exit', function (code) { /* handle exit */ });