These are chat archives for rosshinkley/nightmare

20th
Dec 2017
Nastia Pavliuk
@NastiaPavliuk
Dec 20 2017 15:36
Hi there. I need help. I try to add my extension to electron, but it's doesn't work
` var Nightmare = require('nightmare');
var args = {
openDevTools: {
mode: 'detach'
},
show: true,
alwaysOnTop: true,
electronPath: require('../node_modules/electron')
};
var nightmare = Nightmare(args);
var addLinkMatch = function () {
    return function(Nightmare) {
        console.log("some")
        Nightmare.action('addLinkMatch', (name, options, parent, win, renderer, done) => {
                console.log("extension start adding")
                parent.respondTo('addLinkMatch', (done) => {
                    console.log("extension will be added")
                    win.addDevToolsExtension('..//dist').addLinkMatch(done);
                    console.log("extension was added")
                });
                done();
            },
            function (done) {
                this.child.call('addLinkMatch', done);
            });

    }
}
document.getElementById("start").addEventListener("click", function(){
    document.getElementById("status").innerHTML = "Searching for the gem";

    nightmare
        .goto('http://yahoo.com')
        .type('form[action*="/search"] [name=p]', 'github')
        .click('form[action*="/search"] [type=submit]')
        .wait('#main')
        .use(addLinkMatch())

        .evaluate(function () {
            win.addDevToolsExtension()
        })
        .evaluate(function () {
            console.log(document.querySelector('#main .searchCenterMiddle li a').href)
            return document.querySelector('#main .searchCenterMiddle li a').href
        })
        .then(function (result) {
            document.getElementById("results").innerHTML = result;
        })
        .catch(function (error) {
            document.getElementById("results"). innerHtml = "Search failed: " + error;
        });

})
document.getElementById("stop").addEventListener("click", function(){
    nightmare
        .end()
        .then(function (result) {
            document.getElementById("status").innerHTML = "Leaving Nightmare Speechless";
        })
})  `