segment-boneyard / nightmare

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

How do I add nightmare instances to array? #1639

Closed Zebraslive closed 2 years ago

Zebraslive commented 2 years ago

I want to have an array of nightmare instances and reference by index. I've done this before but I can't remember how the syntax is. How can I store each new nightmare instance for referencing later?

for example maybe something like this. I want to push into array but I don't know if this is right way to do it, should I use a separate array or just change nightmare to nightmare[]?


nightmare[] = new Nightmare({
      switches: {
        'ignore-certificate-errors': true
      },
      electronPath: require('./node_modules/electron'),
  show: false
    });```
Zebraslive commented 2 years ago

Never mind, figured it out.

var nightmare_instances;
window.nightmare_instances = [];
function grabLink(url, filenamex, callback = false) {
  window.nightmare_instances[filenamex] = new Nightmare({
      switches: {
        'ignore-certificate-errors': true
      },
      electronPath: require('./node_modules/electron'),
  show: false
    });
window.nightmare_instances[filenamex]
.goto(url)
 .inject('js', storagepath+'/jquery-3.0.0.js')
.wait(400)
.evaluate(function() {

return $('#videolink').text();

})
.end(function(link) {
return callback(link);
})
.then(function() {

});

}