YZYLAB / dream-js

DreamJS is a high-level browser automation library based on NightmareJS
24 stars 3 forks source link

Doesn't load up a browser #2

Closed mohitps7 closed 4 years ago

mohitps7 commented 4 years ago

Trying to run dream-js with electron. After requiring the module, running const dream = new Dream({show: true}) doesn't load up a browser window nor does it show any errors.

YZYLAB commented 4 years ago

You need to do something with dream for it to pop up Try running the example: https://github.com/YZYLAB/dream-js/blob/master/example.js

mohitps7 commented 4 years ago

Thanks for your response. I am able to clone the repository and run node example.js and it works fine as expected.

However after installing the module and running the example code within my electron app on startup:

const Dream = require('@yzylab/dream-js')
const dream = new Dream({
    show: true,
    openDevTools: { detach: true }
})

dream
    .useragent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36')
    .goto('https://bot.sannysoft.com/')
    .evaluate(function(){
        return document.body.innerHTML;
    })
    .wait(10000)
    .end()
    .then(function(result) {
        console.log(result)
    })

Gives this error: (node:44712) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "file" argument must be of type string. Received type object at validateString (internal/validators.js:112:11) at normalizeSpawnArguments (child_process.js:411:3) at Proxy.spawn (child_process.js:547:16) at Dream.<anonymous> (pathto\node_modules\@yzylab\dream-js\lib\dream.js:126:24) at next (pathto\node_modules\@yzylab\dream-js\lib\dream.js:333:14) at Dream.run (pathto\node_modules\@yzylab\dream-js\lib\dream.js:323:5) at pathto\node_modules\@yzylab\dream-js\lib\dream.js:484:12 at new Promise (<anonymous>) at Dream.then (pathto\Turbo AIO\node_modules\@yzylab\dream-js\lib\dream.js:482:12) at App.<anonymous> (pathto\main.js:56:8)

And running this gives no errors, but nothing is logged and the window isn't opened:

  const Dream = require('@yzylab/dream-js')
  const dream = new Dream({
      show: true,
      openDevTools: { detach: true }
  })

  dream
      .useragent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36')
      .goto('https://bot.sannysoft.com/')
      .evaluate(function(){
          console.log(document.body.innerHTML);
      })
      .wait(10000)
      .end();

Any ideas why?

urbanio commented 4 years ago

Thanks for your response. I am able to clone the repository and run node example.js and it works fine as expected.

However after installing the module and running the example code within my electron app on startup:

const Dream = require('@yzylab/dream-js')
const dream = new Dream({
    show: true,
    openDevTools: { detach: true }
})

dream
    .useragent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36')
    .goto('https://bot.sannysoft.com/')
    .evaluate(function(){
        return document.body.innerHTML;
    })
    .wait(10000)
    .end()
    .then(function(result) {
        console.log(result)
    })

Gives this error: (node:44712) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "file" argument must be of type string. Received type object at validateString (internal/validators.js:112:11) at normalizeSpawnArguments (child_process.js:411:3) at Proxy.spawn (child_process.js:547:16) at Dream.<anonymous> (pathto\node_modules\@yzylab\dream-js\lib\dream.js:126:24) at next (pathto\node_modules\@yzylab\dream-js\lib\dream.js:333:14) at Dream.run (pathto\node_modules\@yzylab\dream-js\lib\dream.js:323:5) at pathto\node_modules\@yzylab\dream-js\lib\dream.js:484:12 at new Promise (<anonymous>) at Dream.then (pathto\Turbo AIO\node_modules\@yzylab\dream-js\lib\dream.js:482:12) at App.<anonymous> (pathto\main.js:56:8)

And running this gives no errors, but nothing is logged and the window isn't opened:

  const Dream = require('@yzylab/dream-js')
  const dream = new Dream({
      show: true,
      openDevTools: { detach: true }
  })

  dream
      .useragent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36')
      .goto('https://bot.sannysoft.com/')
      .evaluate(function(){
          console.log(document.body.innerHTML);
      })
      .wait(10000)
      .end();

Any ideas why?

check https://github.com/segmentio/nightmare/issues/1018

mohitps7 commented 4 years ago

Thank you for your response @urbanio, after looking through the NightmareJS errors I realised I needed to add this option when instantiating the Dream browser:

const dream = new Dream({
  show: true,
  electronPath: require('./node_modules/electron')
})

This issue has been fixed now, thank you!