Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2 instances with shared partition aren't fully sharing session #1029

Closed
shmatt05 opened this issue Mar 3, 2017 · 7 comments
Closed

2 instances with shared partition aren't fully sharing session #1029

shmatt05 opened this issue Mar 3, 2017 · 7 comments
Labels

Comments

@shmatt05
Copy link

shmatt05 commented Mar 3, 2017

I am opening 2 instances under the same "partition" string, note I am not using persist: but reading nightmare and electron docs, equal partition should be enough to share session

What's happening is - If I print cookies I see both share the same cookies, but If I do something like adding to cart in an ecommerce website:

What I expect: both windows to show item in cart, like if I had 2 chrome tabs on the same ecommerce website

What I get: even though on the same partition, one window shows the item in cart, the other shows an empty cart

var browser1 = Nightmare({
        show: false,
        alwaysOnTop: false,
        webPreferences: {
            partition: "test"
        }
});
var browser2 = Nightmare({
        show: false,
        alwaysOnTop: false,
        webPreferences: {
            partition: "test"
        }
});

If it helps the 2 browsers aren't being created at the same time, but with a few minutes difference.

I'd appreciate any feedback if anyone has some, thanks

@entrptaher
Copy link
Contributor

Too many bugs stating the same problem, yet not fixed properly,
https://github.com/segmentio/nightmare/issues?utf8=%E2%9C%93&q=persist, #1024 and more.

I'm replying with additional test information on par with the OP provided details.

var Nightmare = require('nightmare');

var browser1 = Nightmare({
    show: true,
    alwaysOnTop: false,
    webPreferences: {
        partition: "persist: test"
    }
});
var browser2 = Nightmare({
    show: true,
    alwaysOnTop: false,
    webPreferences: {
        partition: "persist: test"
    }
});

setTimeout(() => {
    browser1
        .authentication("user", "passwd")
        .goto("https://httpbin.org/basic-auth/user/passwd")
        .screenshot('test-1.png')
        .then(() => {
            console.log('done 1')
        })
}, 0)

setTimeout(() => {
    browser2
        //.authentication("user", "passwd")
        .goto("https://httpbin.org/basic-auth/user/passwd")
        .screenshot('test-2.png')
        .then(() => {
            console.log('done 2')
        })

}, 3000)

This code is supposed to persist, but the first window returns the desired output, second one remains empty.

@yeeezy
Copy link

yeeezy commented Mar 8, 2017

also getting the same issues with similar code

@rosshinkley
Copy link
Contributor

#1024 is different, for what it's worth: that's talking about a child window. Popups are, for now, not going to work (unless you create the windows yourself, like with nightmare-window-manager). See #593.

Memory serving, partitioning has never worked particularly reliably, but I thought that in your case @entrptaher that the browser1 instance had to end to write the session to disk to then consequently get picked up by browser2? Also, what, exactly, would be getting persisted? The login cookie?

@entrptaher
Copy link
Contributor

entrptaher commented Mar 17, 2017

Okay, so I tried this and it did not work. Yes, the whole session and cookies was supposed to work.

Tried putting them into separate files. Did not work, tried in same file, did not work.

var Nightmare = require('nightmare');

setTimeout(() => {
    var browser1 = Nightmare({
        show: false,
        alwaysOnTop: false,
        webPreferences: {
            partition: "persist: test"
        }
    });
    
    browser1
        .authentication("user", "passwd")
        .goto("https://httpbin.org/basic-auth/user/passwd")
        .screenshot('test-1.png')
        .evaluate(()=>{
          return document.body.innerText
        })
        .end()
        .then((result) => {
            if(result == "") {
              console.log('result 1 is empty')
            } else{
              console.log(`result 1 ${JSON.parse(result)}`)
            }
        })
}, 0)

setTimeout(() => {
    var browser2 = Nightmare({
        show: false,
        alwaysOnTop: false,
        webPreferences: {
            partition: "persist: test"
        }
    });

    browser2
        //.authentication("user", "passwd")
        .goto("https://httpbin.org/basic-auth/user/passwd")
        .screenshot('test-2.png')
        .evaluate(()=>{
          return document.body.innerText
        })
        .end()
        .then((result) => {
            if(result == "") {
              console.log('result 2 is empty')
              } else{
              console.log(`result 2 ${JSON.parse(result)}`)
            }
            
        })

}, 5000)

result

> node test.js
result 1 [object Object]
result 2 is empty

It might be a bug?

@piotr-cz
Copy link

piotr-cz commented May 31, 2017

I'm having similar problem with minimal test case when trying to persist login cookie across nightmare instances.
Did you guys try running nightmare test?

I'm not able to as I'm on windows machine (make is not available) and vagrant box is terminal-only.

@piotr-cz
Copy link

Sorry, false alarm, cookies are working for me.
In my test case I was starting with opening an URL of logout link 🤦‍♂️ so app logged out an user and showed login form.

@matthewmueller
Copy link
Contributor

Hey folks,

The reason this issue isn't working is because every time you call Nightmare(...), you're getting a new electron process with it's own memory.

In my mind you have 2 options here:

  1. Use the same nightmare instance for browser1 and browser2
  2. Use the persist: prefix and load from a flushed session

There's a couple other gotchas around that with persistent sessions and new windows that we'll be looking to address soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

7 participants