User:Sjha3/PhantomJS

From Wikipedia, the free encyclopedia
PhantomJS
Original author(s)Ariya Hidayat
Developer(s)Ariya Hidayat
Initial releaseJanuary 17, 2011 (2011-01-17)
Stable release
2.0.0 / January 23, 2015 (2015-01-23)
Written inC++
TypeHeadless browser
LicenseBSD
Websitephantomjs.org

PhantomJS is a scripted, headless browser used for automating web page interaction. PhantomJS provides a JavaScript API enabling automated navigation, screenshots, user behavior and assertions making it a common tool used to run browser-based unit tests in a headless system like a continuous integration environment. PhantomJS is based on Webkit making it a similar browsing environment to Safari and Google Chrome (before Chrome's fork of webkit evolved into Blink). It is open-source software released under the BSD License.

History[edit]

PhantomJS was released January 23, 2011 by Ariya Hidayat after several years in development.[1]

The first commit to the public project was in 2011.[2] The project has maintained a steady level of weekly contributions from December 26, 2010 to present.[3] As of October 4 2015, the project’s open source code repository is watched by 899 people and contribution is done by 115 people. Also as of October 4 2015, the project has 1704 open issues and 1476 closed issues. [4]

The major releases and features added in those releases are mentioned in the below table.[5]

Release Release Date Features Added
PhantomJS 2.0 January 23, 2015 Core switched to Qt5
PhantomJS 1.8 "Blue Winter Rose" December 21, 2012 Integrated GhostDriver, a remote Webdriver implementation
PhantomJS 1.5 "Ghost Flower" March 20, 2012 Pure headless software for Linux version
PhantomJS 1.3 " Water Lily" September 23, 2011 File System support and mouse events
PhantomJS 1.2 "Birds of Paradise" June 21, 2011 Network traffic monitoring and Rasterization
PhantomJS 1.1 "Cherry Blossom" April 27, 2011 Disk cache, file upload , GIF output and network proxy

Features[edit]

  • Multiplatform : It is available on major platforms like Windows, Mac, Linux etc.
  • Native implementation of web standards : Document Object Model , CSS , SVG , JavaScript and Canvas.
  • Pure headless on Linux : GUI is not needed for compiling and using PhantomJS in a system. This feature is useful for web service platforms and continuous integration systems.
  • REPL : Read Evaluate Print Loop is the feature which is an interactive model provided from version 1.5. Every line (Read) is sent to interpreter, which evaluates (Evaluation) and provides feedback (Print) immediately.[6]

Usage[edit]

  • Headless Web Testing : This method is used for testing using command line without the need for browser. It supports multiple test frameworks like Jasmine (JavaScript framework) and QUnit [7].
  • Network Monitoring : It can be used to analyse network performance, track requests and responses during page loading and export as standard .har format.

Given example shows how to send a http post request to a test server[8]

var page = require('webpage').create(),
    server = 'http://posttestserver.com/post.php?dump',
    data = 'universe=expanding&answer=42';

page.open(server, 'post', data, function (status) {
    if (status !== 'success') {
        console.log('Unable to post!');
    } else {
        console.log(page.content);
    }
    phantom.exit();
});
  • Web Page Automation : Automation can be done easily by loading and manipulating web pages using Document Object Model api.

Given example shows how to search pizza places near Raleigh using yelp.com.[9]

var page = require('webpage').create(),
    url = 'http://lite.yelp.com/search?find_desc=pizza&find_loc=27606&find_submit=Search';

page.open(url, function (status) {
    if (status !== 'success') {
        console.log('Unable to access network');
    } else {
        var results = page.evaluate(function() {
            var list = document.querySelectorAll('address'), pizza = [], i;
            for (i = 0; i < list.length; i++) {
                pizza.push(list[i].innerText);
            }
            return pizza;
        });
        console.log(results.join('\n'));
    }
    phantom.exit();
});
  • Screen Capture : It can be used to capture the contents of a web page including HTML, CSS, SVG and canvas.

Given example shows how to capture wikipedia home page and save it as an image. [10]

var page = require('webpage').create();
page.open('http:://www.wikipedia.org', function () {
  page.render('wikipedia.png');
  phantom.exit();
});


Tools using PhantomJS[edit]

CasperJS[edit]

Shortly after the release of PhantomJS, Nicolas Perriault wrote CasperJS, a suite of libraries on top of PhantomJS that extend its capabilities as a client for automated web page testing. CasperJS and PhantomJS have become valuable enough that similar projects have started to adopt the API as a standard way of interacting with headless browsers.[11][12]

YSlow[edit]

Yahoo! developed a version of YSlow that leverages PhantomJS for to gather performance metrics for websites.[13]

Companies using PhantomJS[edit]

  • Twitter is using QUnit and PhantomJS for unit testing.[14]
  • LinkedIn is using PhantomJS based tools for performance testing.[15]
  • Netflix is using Sketchy, a headless browser built with PhantomJS to understand what it’s doing without having to visit the site.[16]
  • Time Warner Cable is using PhantomJS with CoffeeScript, Jasmine, and JUnit XML for Jenkins continuous integration.[17]

Other uses for PhantomJS[edit]

PhantomJS was made for programmatic control of web sites and has been used for many purposes from visual differencing of websites[18] to automated testing of JavaScript frameworks.[19]

Server Rendering of Client Side JavaScript[edit]

With the rise of client-side JavaScript and the SEO problems that practice presents, developers turned to PhantomJS as a way to pre-render static HTML for initial requests,.[20][21] Despite the performance impact of such an approach, it remained one of the simplest ways to improve SEO without rewriting a web application, spawning services trying to automate the process.[22]

Malicious use of PhantomJS[edit]

Because PhantomJS is runnable without a UI, scriptable via JavaScript, and is relatively adherent to modern browser specifications, it is commonly used as a way to automate attacks against web sites.[23] PhantomJS mimics legitimate user traffic and can complicate attack mitigation technologies. PhantomJS can also be used to automatically verify logins across disparate web sites[24], compounding the problems that arise after a site is breached and usernames and passwords are leaked.

Open Source Projects Using PhantomJS [25][edit]

Books and Articles on PhantomJS[edit]

  • Book "Testable Javascript" by O'Reilly Media [26] has a sub-chapter on PhantomJS page 95.
  • Book "PhantomJS Cookbook" by Packt publisher[27]
  • Book "Getting Started with PhantomJS" by Pact publisher[28]
  • Article on Threatpost mentioning PhantomJS in relation to security.[29]

See also[edit]

References[edit]

  1. ^ "don't code today what you can't debug tomorrow". ariya.blogspot.com. Retrieved 20 July 2015.
  2. ^ "ariya/phantomjs". GitHub. Retrieved 4 October 2015.
  3. ^ "Contributors to ariya/phantomjs · GitHub". GitHub. Retrieved 4 October 2015.
  4. ^ "PhantomJS Issues".
  5. ^ "Major releases of PhantomJS". Retrieved 4 October 2015.
  6. ^ "REPL support in PhantomJS". Retrieved 4 October 2015.
  7. ^ "QUnit".
  8. ^ "Network Monitoring Example". Retrieved 4 October 2015.
  9. ^ "Page Automation Example". Retrieved 4 October 2015.
  10. ^ "Screen Capture". Retrieved 4 October 2015.
  11. ^ Laurent Jouanneau. "FaQ - SlimerJS". slimerjs.org. Retrieved 20 July 2015.
  12. ^ "trifleJS". trifleJS. Retrieved 20 July 2015.
  13. ^ Marcel Duran. "YSlow - Official Open Source Project Website". yslow.org. Retrieved 20 July 2015.
  14. ^ "Leo Lanese on Twitter". Twitter. Retrieved 20 July 2015.
  15. ^ phegaro. "LinkedIn Mobile: How do we do it?". SlideShare. Retrieved 20 July 2015.
  16. ^ Michael Mimoso. "Netflix Open Source Security Tools Solve Range of Challenges". threatpost.com. Retrieved 20 July 2015.
  17. ^ "one year of wandering headlessly". ofilabs.com. Retrieved 20 July 2015.
  18. ^ "Huddle/PhantomCSS". GitHub. Retrieved 20 July 2015.
  19. ^ EisenbergEffect. "Docs - Testing with PhantomJS and Jasmine - Durandal". durandaljs.com. Retrieved 20 July 2015.
  20. ^ "Short story about rendering HTML, client side vs server side". eshlox. Retrieved 20 July 2015.
  21. ^ Aaron O'Connell (22 April 2014). "Sever-Side Rendering of Single Page Apps using PhantomJS and Node.js". 42floors.com. Retrieved 20 July 2015.
  22. ^ "BromBone - SEO for your AngularJS, EmberJS, or BackboneJS website". Brombone.com. Retrieved 20 July 2015.
  23. ^ "DDoS Attack Used 'Headless' Browsers In 150-Hour Siege". Dark Reading. Retrieved 20 July 2015.
  24. ^ "Logging in to Amazon using PhantomJS". GitHub Gists. Retrieved 20 July 2015.
  25. ^ "Open Source Projects Using PhantomJS". Retrieved 4 October 2015.
  26. ^ "Testable JavaScript". google.com. Retrieved 20 July 2015.
  27. ^ Rob Friesel. "PhantomJS Cookbook". packtpub.com. Retrieved 20 July 2015.
  28. ^ Aries Beltran. "Getting Started with PhantomJS". packtpub.com. Retrieved 20 July 2015.
  29. ^ Michael Mimoso. "Netflix Open Source Security Tools Solve Range of Challenges". threatpost.com. Retrieved 20 July 2015.
  30. ^ "SlimerJS".
  31. ^ "TrifleJS".
  32. ^ "CasperJS".

External links[edit]

[[Category:C++ software]] [[Category:Web browsers]] [[Category:Cross-platform web browsers]] [[Category:Portable software]] [[Category:Software based on WebKit]] [[Category:Software using the BSD license]] {{DEFAULTSORT:PhantomJS}}