From 090646e8ed93e16283559870c27015bcbe5bd3a4 Mon Sep 17 00:00:00 2001 From: Maciej Brencz Date: Fri, 2 Oct 2015 20:23:55 +0200 Subject: [PATCH] requestsMonitor: pass "recv" and "send" events to npm layer Resolves #559 --- core/modules/requestsMonitor/requestsMonitor.js | 6 +++--- examples/promise.js | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/core/modules/requestsMonitor/requestsMonitor.js b/core/modules/requestsMonitor/requestsMonitor.js index 2b65d4edd..276f395cf 100644 --- a/core/modules/requestsMonitor/requestsMonitor.js +++ b/core/modules/requestsMonitor/requestsMonitor.js @@ -94,7 +94,7 @@ exports.module = function(phantomas) { phantomas.log('req: <%s>', entry.url); - phantomas.emitInternal('send', entry, res); // @desc request has been sent + phantomas.emit('send', entry, res); // @desc request has been sent }); phantomas.on('onResourceReceived', function(res) { @@ -320,11 +320,11 @@ exports.module = function(phantomas) { } if (entry.isBase64) { - phantomas.emitInternal('base64recv', entry, res); // @desc base64-encoded "response" has been received + phantomas.emit('base64recv', entry, res); // @desc base64-encoded "response" has been received } else { phantomas.log('recv: HTTP %d <%s> [%s]', entry.status, entry.url, entry.contentType); - phantomas.emitInternal('recv' , entry, res); // @desc response has been received + phantomas.emit('recv' , entry, res); // @desc response has been received } break; } diff --git a/examples/promise.js b/examples/promise.js index 337bbf526..eb5a183fd 100755 --- a/examples/promise.js +++ b/examples/promise.js @@ -10,7 +10,8 @@ console.log('phantomas v%s loaded from %s', phantomas.version, phantomas.path); run = phantomas('http://google.is', { 'analyze-css': true, - 'assert-requests': 1 + 'assert-requests': 1, + engine: 'webkit2' }); console.log('Running phantomas: pid %d', run.pid); @@ -39,6 +40,10 @@ run.on('milestone', function(milestone) { console.log('Milestone reached: %s', milestone); }); +run.on('recv', function(response) { + console.log('Response #%d: %s %s [HTTP %d]', response.id, response.method, response.url, response.status); +}); + // including the custom once emitted by phantomas modules run.on('domQuery', function(type, query) { console.log('DOM query by %s - "%s"', type, query);