segment-boneyard / nightmare

A high-level browser automation library.
https://open.segment.com
19.54k stars 1.08k forks source link

wait() doesn't work after user make input(mouse or keyboard) #1597

Closed incheon-kim closed 4 years ago

incheon-kim commented 4 years ago

My purpose is user make login themselves and automatically extract cookies and write cookies.txt to use later for authentication.

When I login with type(username, "").type(password,"").click("login-btn"), wait(".logged-in") works. However, if I type in username and password and click login button myself, wait() wouldn't work. It stucks.

Here's the code.

var nightmare = Nightmare({
            show: true,
            electronPath: require("../../../node_modules/electron"),
            pollInterval: 50,
            waitTimeout: 50000
        });

        nightmare
            .goto(target_url)
            .wait(".logged-in")
            .cookies.get()
            .end()
            .then(cookies =>{
                let lines = "#DO NOT SHARE WITH OTHERS! DO NOT UPLOAD THIS FILE ON PUBLIC WEB!\n#THIS IS COOKIES FOR YOUR PORNHUB PREMIUM ACCOUNT TO USE WITH YOUTUBE-DL\n";
                for(var i=0; i<cookies.length; i++){
                    var cookie = cookies[i];
                    if(!cookie.name.includes("_")){
                        lines += `${cookie.domain}\t${cookie.hostOnly}\t${cookie.path}\t${cookie.expirationDate?Math.round(cookie.expirationDate):0}\t${cookie.name}\t${cookie.value}\n`;
                    }
                }
                console.log(lines);
                fs.writeFileSync(path.resolve("./cookies/cookies.txt"), lines);
                resolve(true);
            });
incheon-kim commented 4 years ago

I used nightmare inside electron app and the app using electron@8.1.1.

I changed electronPath to use the electron nightmare originally used.

var nightmare = Nightmare({
            show: true,
            electronPath: require("../../../node_modules/nightmare/node_modules/electron"),
            pollInterval: 50,
            waitTimeout: 50000
        });