I have a site that is behaving differently when I interact with it in a traditional browser versus spooky/casper/phantom. I would like to debug by printing out the entire http header requests and responses to the console or a file to see what is different between my browser and the phantom browser (similar to how I would using developer tools on the browser). How can I get all http request / response including headers in a spooky event handler?
SpookyJs show all HTTP headers
581 Views Asked by Ian Vasquez At
2
There are 2 best solutions below
0
On
I'm controlling CasperJS from a node module via SpookyJS - so using the advice of Artjom B. I was able to determine that I just needed to add an event listener to the CasperJS options JSON passed into SpookyJS when building the object. For anyone using SpookyJS, that code would look roughly like the following:
var Spooky = require( 'spooky' );
var spooky = new Spooky(
{
child: {
'transport' : 'http'
},
casper: {
logLevel: 'debug'
, verbose: true
, onResourceRequested : function( C, requestData, request ){ this.emit('console', JSON.stringify( requestData ) ) }
, onResourceReceived : function( C, response ){ this.emit('console', JSON.stringify( response ) ) }
}
}, function ( err ) {
if ( err ) {
var e = new Error( 'Failed to initialize SpookyJS' );
e.details = err;
throw e;
}
spooky.start( "www.something.com" );
spooky.run();
}
);
spooky.on('console', function (line) {
console.log(line);
});
In CasperJS you can listen to a couple of events to give you additional information.
See
page.onResourceRequestedfor more information.Additionally, you should capture as many screenshots with
casper.capture()as it makes sense in order to understand what is going on.There are also some events that could help you get to see more errors: