1

My project contains few methods that uses node-horseman, but after every server restart, the process will die after I executed something, whatever method it is. For example, I have one method that retrieves a list of Alerts I have in Google Alerts:

* getRSSNames() {
  return new Promise((resolve, reject) => {
    horseman
      .userAgent(this.userAgent)
      .open('https://www.google.com/alerts')
      .evaluate(function() {
        var item = []

        jQuery('#manage-alerts-div li').each(function(key, val) {
          item.push({
            dataId: jQuery(val).attr('data-id'),
            name: jQuery(val).find('.query_div').text(),
            url: jQuery(val).find('a').attr('href')
          })
        })

        return item
      }).then(function(data) {
        resolve(data)
      })
      .close()
  })
}

Success, if I've just initiated the local server. Then, rendering the list in a select, choose one and try to delete it:

* deleteRSSFeed() {
  let feedID = this.feedID.replace(/%3A/g, ':')

  return new Promise((resolve, reject) => {
    horseman
      .userAgent(this.userAgent)
      .open('https://google.com/alerts')
      .evaluate(function(selector) {
        return jQuery('[data-id="' + selector + '"]').find('.delete_button').click()
      }, feedID)
      .then(function(data) {
        resolve(data)
      })
      .close()
  })
}

It will cause the error:

Unhandled rejection HeadlessError: Phantom Process died
    at poll_func (/home/gabriel/Sites/co-report/api/node_modules/node-phantom-simple/node-phantom-simple.js:584:10)
    at /home/gabriel/Sites/co-report/api/node_modules/node-phantom-simple/node-phantom-simple.js:52:7
    at ClientRequest.<anonymous> (/home/gabriel/Sites/co-report/api/node_modules/node-phantom-simple/node-phantom-simple.js:501:11)
    at emitOne (events.js:96:13)
    at ClientRequest.emit (events.js:188:7)
    at Socket.socketErrorListener (_http_client.js:308:9)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at emitErrorNT (net.js:1272:8)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)

I also have a function that logs in in Google. If I login and I refresh my page with the server running, since I logged in and when refreshing it will retrieve the feed list, it will cause the same error. Please, help me.

  • What do you mean by the phrase "reset the server"? – Vaviloff Feb 06 '17 at 10:13
  • I mean to restart the server locally with nodemon. Run again `npm run dev`, for example, or re-save a file, causing the server to auto-restart too. –  Feb 07 '17 at 02:31
  • Have you seen this [issue](https://github.com/johntitus/node-horseman/issues/45)? – Vaviloff Feb 07 '17 at 03:04
  • I do not understand this. My version is far beyond of the bug that had. –  Feb 08 '17 at 06:14
  • Maybe post a minimal script example? – Vaviloff Feb 08 '17 at 06:39
  • Yes. I've posted two codes I've written. Both work, but when I execute one after another it will cause the error. I really do not have a clue why it happens. –  Feb 08 '17 at 06:52

1 Answers1

0

Ok... My solution was to instantiate horseman inside each method. That's it.