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.
Ok... My solution was to instantiate
horsemaninside each method. That's it.