Phantomjs Node - Page.open - Cannot Keep Track Of Multiple Pages
I'm using Phantom Node to interface node with PhantomJS. I'm trying to open pages in parallel, but the issue is that page.open callback function does not pass back the reference to
Solution 1:
Try it like this:
I added a function that is directly executed around the part that opens the page, thus introducing a new scope. Therefore url
won't get mangled (you cannot use rows[i].url
as i will change before your callback is called) and will be available in your callback.
for( j = 0; j < self.queue.length; j++ )
{
// Find an unused page objectif ( self.queue[j] && self.queue[j].hasOwnProperty( 'page' ) && ( ! self.queue[j].page.url || self.queue[j].page.url == '' ))
{
self.logger.info( 'Opening URL in browser', rows[i].url );
(function() {
var url = rows[i].url;
// Start loading page
self.queue[j].page.open.call( self.queue[j].page, url, function( status )
{
self.resetPage( self.queue[ index ]);
if ( status === 'success' )
{
self.updateStatus( url, 'ready' );
}
else
{
self.updateStatus( url, 'failed' );
}
self.removeUrlFromQueue( url )
});
})();
self.updateStatus( rows[i].url, 'processing' );
break;
}
}
Post a Comment for "Phantomjs Node - Page.open - Cannot Keep Track Of Multiple Pages"