These are chat archives for rosshinkley/nightmare

29th
Jul 2016
Ash Nilkanth
@voidmonk
Jul 29 2016 06:14
@rosshinkley thanks for suggesting partition. I came across another issue: process hangs after did-stop-loading event if response is HTTP 304 - segmentio/nightmare#740, besides the previous issue of: error on wait after goto status code check - segmentio/nightmare#737
Yoyo Zhou
@yoz
Jul 29 2016 20:21
Anyone know if it's possible to use plugins when all I have is an instance? e.g. in module 1 I'm using generic-pool to manage Nightmare instances; in module 2 I have a Nightmare instance that I got from module 1. Normally I would say, require(plugin)(Nightmare); can I write require(plugin)(instance.constructor); in this case?
Ross Hinkley
@rosshinkley
Jul 29 2016 20:22
no, not at present
well, at least not one that's documented
Yoyo Zhou
@yoz
Jul 29 2016 20:23
hmm, I'll try it out and report back
Ross Hinkley
@rosshinkley
Jul 29 2016 20:23
the plugin won't be applied to the current instance
memory serving, Nightmare.action() adds an action to the queue that gets executed prior to anything else
that said, i think the queue is exposed, as is child.call
Ross Hinkley
@rosshinkley
Jul 29 2016 20:30
you could do something liiiike
This message was deleted
oops
editing
Ross Hinkley
@rosshinkley
Jul 29 2016 20:37
... that's totally from the hip
... i meant to edit, not delete
nightmareInstance.myMethod = function(done){
  this.child.call('my-method', function() { 
     //logic for the done callback of myMethod
     done();
  })
};

nightmareInstance
  .then(() => {
    return new Promise((resolve, reject) => {
      //where `myMethodBody` is your plugin's Electron method
      nightmareInstance.call('action', 'my-method', String(myMethodBody), (err) => {
        if(err) return reject(err);
        resolve();
      });
    });
  })
  .then(() => {
    //do the rest of your nightmare actions
  })
Yoyo Zhou
@yoz
Jul 29 2016 22:23
yeah, I'm having issues with it now (although I tried something like this before, not knowing that it shouldn't have worked, and it worked, although it looks like it shouldn't) - will look into alternative approaches