Question: How to restart a casperjs process on a tiemout error
Problem I run a crawler which sometimes times out:
[error] [phantom] Wait timeout of 5000ms expired, exiting.
Wait timeout of 5000ms expired, exiting.
Error: TypeError: 'null' is not an object (evaluating 'document.querySelector('#identify tbody tr:nth-of-type(' + (current * 2 + 2) + ') div.details>div').innerHTML')
Not working solution I put all my casper script into a function which I want to restart on the timeout event:
runCasper = () ->
console.log ">>>>>>>>>>>>>>>>>>STARTING CASPER<<<<<<<<<<<<<<<<<<<<<<"
#Starts Casper and Takes a Snapshot
casper.start(url, () ->
self = this
this.viewport(1024, 768, ()->
self.capture('screenshotsKv/start.png')
)
)
#Iterate through all
.eachThen(plz, (response) ->
lots of code
.on( 'wait.timeout', (msg) ->
this.echo( 'Error: ' + msg, 'ERROR' )
log.aborted = log.aborted.concat(log.last + ' ' + new Date().toString())
functionsFiles.saveLog(log)
self.capture('screenshotsKv/' + log.last + ' ' + new Date().toString() + '.png')
runCasper()
)
#Save all results into the database
.run(() ->
this.exit()
)
#Starts Casper
runCasper()
I also tried step.timeout
but both don't trigger the restart.
Possible reasons (imho):
- because the whole process terminates including the .on listener?
- the listener is wrong?
- the timeout is from phantom and the listener is limited to casperjs?