These are chat archives for rosshinkley/nightmare

8th
Jun 2016
Rob Brackett
@Mr0grog
Jun 08 2016 01:04
@vkarpov Looking through Electron's source code, it does not look like you can manipulate geolocation (other than denying it outright with session.setPermissionRequestHandler() (http://electron.atom.io/docs/api/session/#sessetpermissionrequesthandlerhandler)
The patching with evaluate() is likely problematic because it comes too late. You could monkey-patch in a custom preload script: https://github.com/segmentio/nightmare#custom-preload-script
Ross Hinkley
@rosshinkley
Jun 08 2016 02:02
@Mr0grog off the top of your head, does the geolocation stuff honor a proxy if set?
(i didn't look too closely)
Rob Brackett
@Mr0grog
Jun 08 2016 02:03
not a clue, though I would presume so
Ross Hinkley
@rosshinkley
Jun 08 2016 02:06
you could probably mangle it that way too, push come to shove
i thought chromium had a facility to set the geoip service
but evidently remembered incorrect
Rob Brackett
@Mr0grog
Jun 08 2016 02:09
it does, I think, but Electron hardcodes the URL
Ross Hinkley
@rosshinkley
Jun 08 2016 02:09
ah, right you are
bummer
Ross Hinkley
@rosshinkley
Jun 08 2016 02:31
aaand there, for better or worse, 2.5.1 is out
Selwyn
@Siilwyn
Jun 08 2016 09:33
yay :confetti_ball:
Hi there people, I'm trying to call the function App.room.play on: http://jukebox.today/testroom with nightmare. I can successfully connect to the website and read the content but for some reason the play function does get set to {} instead of a function... The website uses Backbone.js if that helps, I'm clueless after hours of trying. What's weird is that I can fire a click event on the play/pause button which in turn executes the App.room.play function without a problem.
const Nightmare = require('nightmare');
const nightmare = Nightmare({
    show: true
});

nightmare.goto('http://jukebox.today/testroom')
    .wait('.load-complete')
    .wait(3000)
    .evaluate(function() {
        window.App.room.play();
    })
    .wait(3000)
    .end()
    .then();
I think I'm confused about the scope or something since I can access the function from the electron console... :/
coyotte508
@coyotte508
Jun 08 2016 09:46
@Sillwyn your code works for me
(nightmare version 2.5.0)
Selwyn
@Siilwyn
Jun 08 2016 09:49
@coyotte508 that's strange, are you sure?
It doesn't throw an error but it doesn't seem to execute the play function for me.
const Nightmare = require('nightmare');
const nightmare = Nightmare({
  show: true
});

nightmare
  .goto('http://jukebox.today/testroom')
  .wait('.load-complete')
  .wait(3000)
  .evaluate(function () {
      return window.App.room;
  })
  .end()
  .then(function (roomData) {
    console.log('roomData', roomData.play);
  });
@coyotte508 what about this, does it return a function for you? Mine throws undefined
coyotte508
@coyotte508
Jun 08 2016 09:51
i'm not sure it should return a function when moving across context
hold on
Selwyn
@Siilwyn
Jun 08 2016 09:55
Just to clarify my intention. I would like to create a bot that can do add & remove songs, play & pause, etc.
But since the website doesn't have any API I figured this would be the only way.
coyotte508
@coyotte508
Jun 08 2016 09:56
ok so
Your first code does work (The song is paused and then starts playing)
Your second code doesn't - I really don't think you can pass functions back to your nodejs file
when just doing console.log("roomData", roomData) I see all the data that would show when converting to a JSON, but not the functions
Selwyn
@Siilwyn
Jun 08 2016 09:57
oooh
coyotte508
@coyotte508
Jun 08 2016 09:58
you have to keep in mind that the node process and the electron process are separate and so you can pass data across them, even a function to evaluate in the other's context but not functions themselves (idk if I'm being confusing)
Selwyn
@Siilwyn
Jun 08 2016 09:59
No I think I get what you mean.
It still doesn't play for me though...
coyotte508
@coyotte508
Jun 08 2016 09:59
that's my experience at least but maybe @rosshinkley knows a way (I'm still pretty new to it)
well if you do console.log in the evaluated function it should show in the Electron's developer console so you can debug there
.evaluate(function() { console.log('play function', App.room.play); App.room.play();})
Selwyn
@Siilwyn
Jun 08 2016 10:04
@coyotte508 oh yeah that's a nifty idea thanks!
Just discovered what is wrong
can't believe I struggled so many hours at this :facepalm:
coyotte508
@coyotte508
Jun 08 2016 10:05
so... what is it?
Selwyn
@Siilwyn
Jun 08 2016 10:06
the play function does only call locally and clicking the play button also sends a message to the server to play the song. So I have to call onPlayClicked instead.
didn't expect logic in the clicked function
would be better if the author but it in play I think :|
either way, YES! finally
now I just need to find a way to call that function ;d
coyotte508
@coyotte508
Jun 08 2016 10:09
well, your code did act as though the song was played (the time started ticking) but I can't get any sound either way
Selwyn
@Siilwyn
Jun 08 2016 10:09
indeed, since the client and server are out of sync that way it doesn't really play
e.g. this does work:
const Nightmare = require('nightmare');
const nightmare = Nightmare({
  show: true
});

nightmare
  .goto('http://jukebox.today/testroom')
  .wait('.load-complete')
  .click('.js-play')
  .wait(10000)
  .evaluate(function () {
    console.log('play function', App.room.play);
    console.log('play function', window.App.room.play);
    // window.App.room.play();
  })
  .wait(3000000)
  .end()
  .then(function (result) {});
Now I try to call the onclick function directly, just gotta figure out where it resides
coyotte508
@coyotte508
Jun 08 2016 10:11
why do you need to call it directly anyway?
and not just click on buttons
Selwyn
@Siilwyn
Jun 08 2016 10:13
oh good question, now I remember why I didn't like the button. The button does both: pause & play depending on the state. In hindsight I can use the button and just click it or not based on reading the state myself.
also calling the JS directly feels a bit neater I guess
Ross Hinkley
@rosshinkley
Jun 08 2016 12:46
i know i'm late to this, but for what it's worth, @coyotte508 is right: in general, stuff crossing the IPC - like returning values from .evaluate() - have to be json -serializable
Selwyn
@Siilwyn
Jun 08 2016 18:19
@rosshinkley alright thank you for the confirmation! : )
Selwyn
@Siilwyn
Jun 08 2016 22:19
I love using nightmare. props to all people contributing!