These are chat archives for rosshinkley/nightmare

4th
May 2017
Steven Vachon
@stevenvachon
May 04 2017 01:32
segmentio/nightmare#1124
Ayana Wilson
@awilson28
May 04 2017 13:10
hey folks, I'm probably missing something about how electron works: when I'm crawling a site with nightmare and the code clicks a button that opens a popup window, that window always becomes a login page, not the report that it's supposed to be. But when I'm manually navigating the page, I'm never logged out. I've clicked all the "remember me" buttons with the crawler but the popup still becomes a login page. I changed the crawler to log back in, but when it clicks the button again, it still takes me to a login page. It's a login cycle of death. Why does this happen when it never happens when I'm navigating the site manually?
johnferro
@johnferro
May 04 2017 15:14
@awilson28 I'm not 100% sure but nightmare might have problems with multiple windows. Have you tried getting the url that is supposed to be opened and manually going to it within the main window instead of clicking the button?
Ayana Wilson
@awilson28
May 04 2017 15:31
@johnferro hey thanks for responding -- yeah so I installed nightmare-window-manager and used its API to grab the URL of the new window and then executed nightmare.goto(newWindow.url), which takes me to the login page, and I log in, try to access the report, but find myself in the same situation -- the popup opens into a login page
So it's a never ending loop of clicking the button to access the report > popup window opening into login page > logging in > clicking the button to access the report > popup window opening into login page > logging in, etc,
and I can't figure out why this happens since it is entirely unlike the behavior when I encounter when I navigate the site manually
johnferro
@johnferro
May 04 2017 16:42
@awilson28 Hmmm, after you login can you access the report through a url so that it doesn't open a popup - or does even navigating to that url open a popup?
Ayana Wilson
@awilson28
May 04 2017 16:44
@johnferro unfortunately if I navigate to the URL directly, it won't open because the page depends on functionality attached to the originating window. It loads the data via window.opener.loadData() so that it's impossible to access the data via bypassing the popup
johnferro
@johnferro
May 04 2017 16:53
Do you know how the login state is being stored? If you just refresh the page do you remain logged in?
Maybe try setting the webPreferences.partition value as document here (https://github.com/electron/electron/blob/master/docs/api/browser-window.md#new-browserwindowoptions)
Ayana Wilson
@awilson28
May 04 2017 17:01
@johnferro thanks for this suggestion, just checked out the documentation but I'm a tad confused as to how the partition should be used... to what value would I set webPreferences.partition?
johnferro
@johnferro
May 04 2017 17:15
@awilson28 I'm not sure if it has to be set to anything in particular. It could just be a matter of it getting set to something so that its shared between the windows. The only thing documented is that if it doesn't start with persist: then it will be in-memory. I'm not sure if that matters or not to your situation

For example:

Nightmare({
  width: 1400,
  height: 1200,
  webPreferences: {
    partition: 'shared-session'
  }
});

or

Nightmare({
  width: 1400,
  height: 1200,
  webPreferences: {
    partition: 'persist:shared-session'
  }
});
Ayana Wilson
@awilson28
May 04 2017 17:19
@johnferro awesome, thank you for this, I'll try it out now ~
!
Ayana Wilson
@awilson28
May 04 2017 18:23
@johnferro it worked! So now I'm no longer being logged out. But there's still the problem of how to access the new window which does generate the report... I'm essentially running up against this issue: electron/electron#1865
johnferro
@johnferro
May 04 2017 18:48
@awilson28 Glad that part worked out. That issue looks like its related to accessing the content/context of one window from the other window within the electron process. However, can you use the nightmare-window-manager to select the appropriate window on the node level?
Ayana Wilson
@awilson28
May 04 2017 18:54
@johnferro it seems that my ability to access the new window is quite limited even with nightmare-window-manager ... and with the electron 1865 issue ( with the site I'm working on, the new window references the old window via window.opener and uses functionality stored on that object to load the data I want), I'm not sure it makes sense / will be efficient to continue using nightmarejs for this... I think it'd only make sense if I were certain that once I figured out the 1865 issue, I'd be able to fully control and access data from the new window
@johnferro I really appreciate your help!
johnferro
@johnferro
May 04 2017 19:29
@awilson28 Ah I think I misunderstood you before. Yeah if those two windows require communication between each other for the content within them to work then 1865 would be a problem. Based on the discussion within that issue it looks like you might be able to use the sandbox option that's documented in the same place that the partition option is. However, I don't have any experience using it so not sure if it would work for you. @rosshinkley might be able to answer any questions you have on the capabilities of nightmare-window-manager