TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: Nightmare – Simple browser automation

429 pointsby pkreinover 10 years ago

30 comments

tucosanover 10 years ago
Even after substituting the fancy ampersands on your homepage, and requiring nightmare your example still does not run:<p><pre><code> var Nightmare = require(&#x27;nightmare&#x27;); new Nightmare() .goto(&#x27;http:&#x2F;&#x2F;yahoo.com&#x27;) .type(&#x27;input[title=&quot;Search&quot;]&#x27;, &#x27;github nightmare&#x27;) .click(&#x27;.searchsubmit&#x27;) .run(); </code></pre> yields:<p><pre><code> node yahoo.js phantom stdout: TypeError: &#x27;null&#x27; is not an object (evaluating &#x27;element.value = text&#x27;) phantom stdout: phantomjs:&#x2F;&#x2F;webpage.evaluate():3 phantomjs:&#x2F;&#x2F;webpage.evaluate():4 phantomjs:&#x2F;&#x2F;webpage.evaluate():4 stream.js:94 throw er; &#x2F;&#x2F; Unhandled stream error in pipe. ^ TypeError: undefined is not a function at next (&#x2F;private&#x2F;tmp&#x2F;night&#x2F;node_modules&#x2F;nightmare&#x2F;lib&#x2F;index.js:56:23) at f (&#x2F;private&#x2F;tmp&#x2F;night&#x2F;node_modules&#x2F;nightmare&#x2F;node_modules&#x2F;once&#x2F;once.js:16:25) at Proto.apply (&#x2F;private&#x2F;tmp&#x2F;night&#x2F;node_modules&#x2F;nightmare&#x2F;node_modules&#x2F;phantom&#x2F;node_modules&#x2F;dnode&#x2F;node_modules&#x2F;dnode-protocol&#x2F;index.js:123:13) at Proto.handle (&#x2F;private&#x2F;tmp&#x2F;night&#x2F;node_modules&#x2F;nightmare&#x2F;node_modules&#x2F;phantom&#x2F;node_modules&#x2F;dnode&#x2F;node_modules&#x2F;dnode-protocol&#x2F;index.js:99:19) at D.dnode.handle (&#x2F;private&#x2F;tmp&#x2F;night&#x2F;node_modules&#x2F;nightmare&#x2F;node_modules&#x2F;phantom&#x2F;node_modules&#x2F;dnode&#x2F;lib&#x2F;dnode.js:140:21) at D.dnode.write (&#x2F;private&#x2F;tmp&#x2F;night&#x2F;node_modules&#x2F;nightmare&#x2F;node_modules&#x2F;phantom&#x2F;node_modules&#x2F;dnode&#x2F;lib&#x2F;dnode.js:128:22) at SockJSConnection.ondata (stream.js:51:26) at SockJSConnection.EventEmitter.emit (events.js:107:17) at Session.didMessage (&#x2F;private&#x2F;tmp&#x2F;night&#x2F;node_modules&#x2F;nightmare&#x2F;node_modules&#x2F;phantom&#x2F;node_modules&#x2F;shoe&#x2F;node_modules&#x2F;sockjs&#x2F;lib&#x2F;transport.js:220:25) at WebSocketReceiver.didMessage (&#x2F;private&#x2F;tmp&#x2F;night&#x2F;node_modules&#x2F;nightmare&#x2F;node_modules&#x2F;phantom&#x2F;node_modules&#x2F;shoe&#x2F;node_modules&#x2F;sockjs&#x2F;lib&#x2F;trans-websocket.js:102:40) </code></pre> The examples in the githubs pages readme don&#x27;t run either. I am too lazy to debug this.
评论 #8418785 未加载
评论 #8418018 未加载
pkreinover 10 years ago
Quick example of how we use this at Segment... for each integration (<a href="https://segment.io/integrations" rel="nofollow">https:&#x2F;&#x2F;segment.io&#x2F;integrations</a>) we need to create a vector logo. This got a bit tedious after the first 50 :) so we built nightmare + nightmare-swiftly so that our chat bot could &quot;auto-generate&quot; vector logos: <a href="https://cloudup.com/cEA-dTd3glM" rel="nofollow">https:&#x2F;&#x2F;cloudup.com&#x2F;cEA-dTd3glM</a><p>Hope it&#x27;s helpful!
评论 #8418599 未加载
评论 #8419167 未加载
评论 #8417241 未加载
ssharpover 10 years ago
Could I accomplish multi-page form automation doing something like:<p><pre><code> .goto(page1) &#x2F;&#x2F; page 1 .type(&#x27;selector&#x27;, &#x27;value&#x27;) .click(&#x27;selector&#x27;) .wait() &#x2F;&#x2F; page 2 .type(&#x27;selector&#x27;, &#x27;value&#x27;) .click(&#x27;selector&#x27;) .wait() </code></pre> etc. ?<p>If so, that seems super easy and more straightforward than vanilla Shadow or even Casper.
评论 #8417386 未加载
resu_nimdaover 10 years ago
I&#x27;ve been wanting to programmatically get my transaction details from my bank for a while. I knew about phantomJS but never got around to trying it out. When I saw this I decided to give it a shot, and within half an hour I was able to log into my bank&#x27;s website (a complicated multi-step process that I had failed to achieve with just POST requests).<p>Nice tool, thanks. The debugging could use a bit of work - whenever something went wrong it just spit out a bunch of &quot;null is not an object&quot; messages from phantom. Overall it was very easy to use though.
评论 #8419506 未加载
评论 #8418114 未加载
mknittigover 10 years ago
Looks like DalekJS (<a href="http://dalekjs.com/" rel="nofollow">http:&#x2F;&#x2F;dalekjs.com&#x2F;</a>)
评论 #8418551 未加载
评论 #8417023 未加载
评论 #8417472 未加载
wehadfunover 10 years ago
I&#x27;m using casper now but this seems like it may be even easier.
评论 #8421332 未加载
mherrmannover 10 years ago
I am one of the founders of a startup that sells a similar, proprietary library for Python and Java: <a href="http://heliumhq.com" rel="nofollow">http:&#x2F;&#x2F;heliumhq.com</a>. Maybe some of the people reading this will find it interesting.
NoMoreNicksLeftover 10 years ago
It&#x27;s a polished website... and I know what javascript is, but they didn&#x27;t do a good job of explaining what it is.<p>Browser automation? Is this a test suite of some sort, something like selenium? Or is it more like Mechanize?
IanDrakeover 10 years ago
I do like the work they&#x27;ve done with Phantom but the API is horrendous and I found myself wrapping the parts I used. Nightmare looks more complete and probably better tested than my wrapper. Well done.
ryanackleyover 10 years ago
Looks like an interesting library. I have no use for it right now but maybe one day. Definitely can see why this would be useful for some people though.<p>Their website has some serious style. It looks cool and original. Which raises a meta-issue that has been bugging me for a while. This is the bar you have to meet for even an open source project nowadays. It&#x27;s not enough for you to pour your blood sweat and tears into something and then give it away for free. You then have to create slick looking site to market it and get people&#x27;s attention.
评论 #8420048 未加载
novaleafover 10 years ago
obligatory self-promotion, for those interested in an easy to use PhantomJs: <a href="https://PhantomJsCloud.com" rel="nofollow">https:&#x2F;&#x2F;PhantomJsCloud.com</a>
评论 #8417667 未加载
thinkvitaminover 10 years ago
I use Ubuntu Linux, and I&#x27;ve got PhantomJS installed. Whether I use Nightmare, Nightmarejs, or Phantomjs on the command line this is what I get: ReferenceError: Can&#x27;t find variable: Nightmare<p><pre><code> nightmare.js:1 </code></pre> Should there be more instructions for installing? I believe the brew command is something for Mac users only...
chenglouover 10 years ago
Shameless plug: I maintain Node-huxley (<a href="https://github.com/chenglou/node-huxley" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;chenglou&#x2F;node-huxley</a>), which accomplishes what this project does, but without the need for writing automation code. Also compares previous&#x2F;next screenshots for you automatically.
ankit84over 10 years ago
How is it different from <a href="http://nightwatchjs.org/" rel="nofollow">http:&#x2F;&#x2F;nightwatchjs.org&#x2F;</a> ?
评论 #8421475 未加载
评论 #8416960 未加载
评论 #8416963 未加载
thathonkeyover 10 years ago
I currently only have experience using CasperJS which also wraps-around PhantomJS. This has different goals (simpler) and therefore a simpler API, though. The use case at Segment (automatically generating vector logos from a given graphic) is even cooler though, I think! Thanks for sharing!
dutzi_over 10 years ago
Nice work!<p>Can you please provide an example for using `evaluate()` to get the page&#x27;s content?<p>I tried this, but didn&#x27;t get anything:<p><pre><code> new Nightmare() .goto(&#x27;http:&#x2F;&#x2F;yahoo.com&#x27;) .evaluate(function (page) { return this.content; }, function (res) {console.log(res);}) .run();</code></pre>
评论 #8421040 未加载
andrey-pover 10 years ago
And, if you want a very very thin wrapper around Phantom (essentially a phantom script manager), feel free to have a look at this instead:<p><a href="https://github.com/andrey-p/ectoplasm-js" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;andrey-p&#x2F;ectoplasm-js</a><p>Pardon the shameless plug.
wearhereover 10 years ago
What is the project&#x27;s background image (<a href="http://www.nightmarejs.org/nightmarejs.org/images/ground.jpg" rel="nofollow">http:&#x2F;&#x2F;www.nightmarejs.org&#x2F;nightmarejs.org&#x2F;images&#x2F;ground.jpg</a>)?
评论 #8418050 未加载
SnowProblemover 10 years ago
As someone entirely unfamiliar with both Nightmare and PhantomJS, what is the typical use case? It isn&#x27;t obvious to me from the examples or FAQs. Why prefer these over something like Selenium?
评论 #8418683 未加载
dylandempseyover 10 years ago
Very nice. FYI best practices are to have a CTA or indicator on your site to scroll down, so no one leaves thinking the whole site is just an image and title.
brianzelipover 10 years ago
Segment usually puts out great tools and crisp sites!
nstartover 10 years ago
Does anyone know how this compares to zombie js? I&#x27;m new to headless browser testing so apologies if question isn&#x27;t relevant
henrygrewover 10 years ago
I&#x27;m building a bot using this, any idea of proxies i can use to change the source ip&#x27;s and how i can use it with a proxy?
tuxoneover 10 years ago
Fantastic easy tool! There is a way to pass phantomjs command line options (eg. --ssl-protocol=X ) through nightmarejs?
评论 #8420728 未加载
brickmortover 10 years ago
Extra points for page design!
fimdomeioover 10 years ago
so... how does one query the DOM? It looks it has been left out of the api. Does this mean that Nightmare is only able to do brainless automation without checking browser results?
oldboyFXover 10 years ago
Interesting background... creepy is good.
niixover 10 years ago
Very nice!
mdanielover 10 years ago
Ordinarily I would file a website bug, but this happens so often I&#x27;m mentioning it here to hopefully stop others from doing it, too.<p><i>Please</i> don&#x27;t use fancy quotes or the fancy apostrophe for code examples on your webpage. It looks out-of-place with the rest of the fixed width font and, most importantly, it stops folks from being able to copy-and-paste your examples into their terminal or editor.
评论 #8418100 未加载
curiouslyover 10 years ago
the problem with Phantom.js is that compared to an actual browser it still falls short. I&#x27;ve given up on Phantom.js all together because it is actually not a true replacement for Selenium running on an actual browser. I found it far more reliable to have Firefox running on Xvfb for when I&#x27;m testing without worrying about Phantom.js behaving wildly.
评论 #8418221 未加载
评论 #8418604 未加载
评论 #8420073 未加载
评论 #8418392 未加载