These are chat archives for rosshinkley/nightmare

22nd
May 2016
Hudson Atwell
@atwellpub
May 22 2016 20:30
Hey is anyone around to answer a few ?s about nightmare?
Ross Hinkley
@rosshinkley
May 22 2016 20:30
shoot
Hudson Atwell
@atwellpub
May 22 2016 20:30
ah cool
I want to gather all the elements in a page and I'm using .then() after a wait... not really sure if that's the right approach bc I can't seem to access the document variable from within it.
Ross Hinkley
@rosshinkley
May 22 2016 20:31
from within... the .then()?
Hudson Atwell
@atwellpub
May 22 2016 20:32
Yeah something like this:
Actions.nightmare
              .goto(Actions.search_url)
              .wait('.container')
              .then(function (result) {
                   var users = document.getElementsByClassName('.card');
                   console.log(users.length);
              })
              .catch(function (error) {
                console.error('Search failed:', error);
              });
sorry new to gitter too
Ross Hinkley
@rosshinkley
May 22 2016 20:33
that's fine... fwiw, you can use markdown like you would for github issues
Hudson Atwell
@atwellpub
May 22 2016 20:33
yeah I just found it today and I'm trying to teach myself by writing a small information gathering bot.
Ross Hinkley
@rosshinkley
May 22 2016 20:33
same syntax, as far as i know
hm...
you can't use document like that inside of a .then() - that function will run in your local context
you're probably after .evaluate()
Hudson Atwell
@atwellpub
May 22 2016 20:35
could I stuff any js code in an evaluate?
Ross Hinkley
@rosshinkley
May 22 2016 20:37
yes, but the .evaluate() js will run under the electron (really, the client page) context
something like...
Actions.nightmare
  .goto(Actions.search_url)
  .wait('.container')
  .evaluate(function(result) {
    return Array.from(document.getElementsByClassName('.card')).map((element)=>{
      return element.innerHTML;
    });
  })
  .then(function(users){
    console.log(users.length);
  })
  .catch(function(error) {
    console.error('Search failed:', error);
  });
that's totally untested and from the hip
Hudson Atwell
@atwellpub
May 22 2016 20:39
pow
Ross Hinkley
@rosshinkley
May 22 2016 20:40
note that document.getElementsByClassName is wrapped in Array.from
this is intentional... the DOMList that getElementsByClassName produces isn't JSON-serializable
Hudson Atwell
@atwellpub
May 22 2016 20:40
oh cool
Ross Hinkley
@rosshinkley
May 22 2016 20:41
trying to avoid an immediate gotcha for you :)
Hudson Atwell
@atwellpub
May 22 2016 20:42
:smile:
It's kind of a distracting day. I'm going to run the suggestions and pop back in and out with my results.
Ross Hinkley
@rosshinkley
May 22 2016 20:42
i totally understand
lmk if you have more questions
Hudson Atwell
@atwellpub
May 22 2016 20:43
One more thing that I have on the table. I'm getting these a lot.
(node) warning: possible EventEmitter memory leak detected. 11 error listeners added. Use emitter.setMaxListeners() to increase limit.
ok ty
ty very much
Ross Hinkley
@rosshinkley
May 22 2016 20:43
(by the by, the domlist thing was segmentio/nightmare#617)
uh, what version are you on?
i know for a fact that we've talked about eventemitter leakage
the issue isn't jumping out at me offhand
segmentio/nightmare#350
but i thought there was another one, and i also thought that particular thing got fixed
oookay, it's evidently not fixed
Ross Hinkley
@rosshinkley
May 22 2016 20:50
maybe we just talked about that here on gitter, i can't recall
Hudson Atwell
@atwellpub
May 22 2016 20:51
I'm not sure.
Ross Hinkley
@rosshinkley
May 22 2016 20:51
anyway! that's a known problem
Hudson Atwell
@atwellpub
May 22 2016 20:51
It's not a consistent thing for me. And it doesn't fatal so that's good.
Could just be a warning
Ross Hinkley
@rosshinkley
May 22 2016 20:51
eventemitter leaks are generally bad
means you're not cleaning up after yourself (bad), which can lead to memory leaks (worse)
Hudson Atwell
@atwellpub
May 22 2016 20:53
Your suggestion worked it returned the value.
Great news.
Ross Hinkley
@rosshinkley
May 22 2016 20:53
:)
Hudson Atwell
@atwellpub
May 22 2016 20:53
I grabbed master from the repo
to answer you
Ross Hinkley
@rosshinkley
May 22 2016 20:53
ah, nice
Hudson Atwell
@atwellpub
May 22 2016 20:54
I am side swiped
will return when the wind dies down
Ross Hinkley
@rosshinkley
May 22 2016 20:54
(also, for completeness: segmentio/nightmare#282)
Hudson Atwell
@atwellpub
May 22 2016 20:54
do you keep this channel open?
Ross Hinkley
@rosshinkley
May 22 2016 20:54
yep, this one's "official" until further notice