Note that there are some explanatory texts on larger screens.

plurals
  1. POHaving trouble running Phantomjs + node on Heroku
    text
    copied!<p>I've successfully got Phantomjs to work on Heroku but now I'm hitting issues with the phantomjs-node interface for node.js (see <a href="https://github.com/sgentle/phantomjs-node" rel="noreferrer">https://github.com/sgentle/phantomjs-node</a>). </p> <p>When I'm attempting to initialize Phantom I'm seeing a 10-15 second delay and then:</p> <pre><code>&gt; phantom stdout: ReferenceError: Can't find variable: socket phantom stdout: phantomjs://webpage.evaluate():1 phantomjs://webpage.evaluate():1 phantomjs://webpage.evaluate():1 </code></pre> <p>You can reproduce the problem with the following steps or by pulling down my test app at <a href="https://github.com/matellis/phantom-test" rel="noreferrer">https://github.com/matellis/phantom-test</a> </p> <pre><code>git init phantom-test cd phantom-test heroku apps:create # create node app as per Heroku instructions here https://devcenter.heroku.com/articles/nodejs # copy bin and lib folders from http://phantomjs.googlecode.com/files/phantomjs-1.6.1-linux-x86_64-dynamic.tar.bz2 into root of your new project # if you don't do this step you'll get an error "phantom stderr: execvp(): No such file or directory" git add . git commit -m "init" git push heroku </code></pre> <p>Test your app has come up, the third to last line will tell you the URL, it should read like:</p> <pre><code>http://fathomless-ravine-5563.herokuapp.com deployed to Heroku </code></pre> <p>If successful you should see Hello World! in your browser.</p> <p>Now from the same folder as your Heroku application run:</p> <pre><code>heroku run node </code></pre> <p>At the node prompt try the following:</p> <pre><code>phantom = require('phantom'); x = phantom.create(); </code></pre> <p>Wait 10-15 seconds and you should see the error. Nothing works from this point on.</p> <p>This should output file <code>foo.png</code>:</p> <pre><code>x = phantom.create(function(ph){ph.createPage(function(page){ page.open('http://bbcnews.com', function(status){ page.render('foo.png', function(result) {ph.exit()}); }); }); }); </code></pre> <p>To validate Phantomjs is working fine on Heroku, try the following using my test project:</p> <pre><code>&gt;heroku run bash Running `bash` attached to terminal... up, run.1 ~ $ phantomjs test.js http://bbcnews.com foo.png ~ $ ls *.png foo.png </code></pre> <p>I cannot reproduce any of these problems locally but there are other issues reported where folks may have hit this issue locally.</p> <p>The problem seems to originate in <code>shim.js</code> line 1637:</p> <pre><code>s.on('request', function(req) { var evil; evil = "function(){socket.emit('message', " + (JSON.stringify(JSON.stringify(req))) + " + '\\n');}"; return controlPage.evaluate(evil); }); </code></pre> <p>I've tried variations of versions of node, phantom, etc. with no luck.</p> <p>I've also tried a custom buildpack that sets the DYLD variable, see <a href="http://github.com/tecnh/heroku-buildpack-nodejs" rel="noreferrer">http://github.com/tecnh/heroku-buildpack-nodejs</a> with no luck either.</p> <p>Anyone who has got Phantom + Node playing together nicely on Heroku please let me know. There are several references to this on Stackoverflow but nobody is saying "I got it to work, here's how".</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload