Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP traffic events not fired #559

Closed
ivangabriele opened this issue Sep 28, 2015 · 5 comments
Closed

HTTP traffic events not fired #559

ivangabriele opened this issue Sep 28, 2015 · 5 comments
Labels
Milestone

Comments

@ivangabriele
Copy link

Hi !

I wrote the code below but the HTTP traffic events (onResourceRequested, onResourceReceived) are never fired :

var fs = require('fs'),
    options,
    phantomas = require('phantomas'),
    phantomasTask,
    ProgressBar = require('progress'),
    progressBar,
    startTime,
    stats,
    url;

url = 'http://www.amazon.com';
options = {
  "engine": "webkit2",
  "timeout": 30
};
progressBar = new ProgressBar('Loading ' + url + ' [:bar] :percent (:elapseds)', {
  complete: '=',
  incomplete: ' ',
  width: 20,
  total: 100
});

console.log();
startTime = Date.now();
phantomasTask = phantomas(url, options);

phantomasTask.on('results', function(results) {
  stats = {
    "metrics": results.getMetrics(),
    "requests": {
      "cssCount": results.getOffenders("cssCount"),
      "htmlCount": results.getOffenders("htmlCount"),
      "imageCount": results.getOffenders("imageCount"),
      "jsCount": results.getOffenders("jsCount"),
      "otherCount": results.getOffenders("otherCount"),
      "webfontCount": results.getOffenders("webfontCount")
    }
  };

  fs.writeFileSync('data/prod/' + Date.now() + '.json', JSON.stringify(stats, undefined, 2));
});

phantomasTask.on('error', function(error) {
  isNaN(error) ? console.error('Exit error: #%s.', error) : console.error('Exit code: #%d.', error);
  process.exit();
});

phantomasTask.on('progress', function(progress, progressDiff) {
  progressBar.tick(progressDiff);
});

phantomasTask.on('onResourceRequested', function(request) {
  console.log(JSON.stringify(request, undefined, 2));
});

phantomasTask.on('onResourceReceived', function(response) {
  console.log(JSON.stringify(response, undefined, 2));
});
@macbre
Copy link
Owner

macbre commented Sep 29, 2015

You should bind to send and recv events. The "core" PhantomJS events are not propagated to phantomas nodejs layer - https://github.com/macbre/phantomas/blob/devel/core/phantomas.js#L623-L631

@macbre macbre closed this as completed Sep 29, 2015
@ivangabriele
Copy link
Author

I tried to use them also and it didn't work :s

@macbre macbre reopened this Oct 2, 2015
@macbre macbre added the bug label Oct 2, 2015
@macbre macbre added this to the v1.13 milestone Oct 2, 2015
@macbre
Copy link
Owner

macbre commented Oct 2, 2015

This is a regression caused by #324 - I'll bring back send and recv events and update the docs on wiki page.

@macbre macbre closed this as completed in 090646e Oct 2, 2015
@macbre
Copy link
Owner

macbre commented Oct 2, 2015

Fixed

@ivangabriele, thanks for reporting!

@ivangabriele
Copy link
Author

And thanks for being so fast to fix it !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants