InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

PhantomJS tutorials

  • Install phantomjs on Mac
  • Install phantomjs on Ubuntu
  • create site snapshot thumbnail
  • find all fonts-families on a web page
  • print resources request by a page
  • skip Google analytics when fetching a web page
 
  • Home
  • > Tutorials
  • > Javascript
  • > PhantomJS

Phantomjs – how to check what resources are being requested by a page

By admin on Dec 5, 2015

Phantomjs lets you add hooks when it fetches a web page. Here is code snippet which can be used to print all resources phantomjs fetches after fetching the main page.

var url = require('system').args[1];
var page = require('webpage').create();
page.onResourceRequested = function (requestData, request) {
  console.log('url requested: ' + requestData.url);
};
page.open(url, function (status) {
  if (status !== 'success') {
    console.log('Unable to access network');
  } else {
    console.log("Done...");
    phantom.exit(0);
  }
});

Save above code as resources.js and run

phantomjs resources.js https://dev.infoheap.com/

Here is the sample outcome (first few lines) which come from running this on Ubuntu Linix:

url requested: https://dev.infoheap.com/
url requested: https://dev.infoheap.com/wp-content/plugins/yet-another-related-posts-plugin/style/widget.css?ver=4.3.1
url requested: https://dev.infoheap.com/wp-content/themes/shell-master/style.css?ver=0.1.1
url requested: https://dev.infoheap.com/wp-content/themes/shell-master/media-queries.css?ver=0.1.1
url requested: https://dev.infoheap.com/wp-content/themes/shell-child-colorful/style.css?ver=0.0.1
url requested: https://dev.infoheap.com/wp-includes/js/jquery/jquery.js?ver=1.11.3
url requested: https://dev.infoheap.com/wp-includes/js/jquery/jquery-migrate.js?ver=1.2.1
url requested: http://www.google-analytics.com/analytics.js
...

Suggested posts:

  1. How to crop an image using imagemagick convert
  2. How to install and run Chrome PageSpeed insights for measuring site performance
  3. How to install phantomjs on Mac
  4. How to install node (node.js) on Mac
  5. Python filter list/iterable examples
  6. Meta robot noindex, follow for wordpress tags and category pages
  7. Make an element draggable using Vanilla Javascript
  8. PHP – Regex OR (alternation) examples using pipe
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged Javascript, Linux, Mac, PhantomJS, Tutorials, Ubuntu Linux
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress