Jump to content

PhantomJS

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Jsoverson (talk | contribs) at 00:56, 12 February 2015 (initial page). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
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)
Repository
Written inC++
TypeWeb 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 off of 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

PhantomJS was released January 23rd, 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 February 5, 2015, the project’s open source code repository is watched by 770 people and contributed to by 107 contributors. Also as of February 5, 2015, the project has 1376 open issues and 1252 closed issues.

The logo commonly used to pictorially refer to PhantomJS is a green ghost atop a black background. This refers to the lack of graphical user interface, or main body of the browser, making PhantomJS users seem like ghosts.

PhantomJS usage

The PhantomJS JavaScript API can be used to open web pages, execute user actions, and run injected JavaScript in the page context. For example, the following code will open Wikipedia and, upon loading, will simply exit.

console.log('Loading a web page');
var page = require('webpage').create();
var url = 'http://en.wikipedia.org/';
page.open(url, function (status) {
  console.log('Page loaded');
  phantom.exit();
});

CasperJS

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[4].

Companies using PhantomJS

  • Twitter is using QUnit and PhantomJS for unit testing[5]
  • LinkedIn is using PhantomJS based tools for performance testing [6]
  • Netflix is using Sketchy, a headless browser built with PhantomJS to understand what it’s doing without having to visit the site. [7]

Other uses for PhantomJS

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

Server Rendering of Client Side JavaScript

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 [10], [11]. 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 [12].

Malicious use of PhantomJS

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[13]. PhantomJS mimics legitimate user traffic and can complicate attack mitigation technologies. PhantomJS can also be used to automatically verify logins across disparate web sites[14] (Credential Stuffing), compounding the problems that arise after a site is breached and usernames and passwords are leaked.

See also

References


Category:C++ software Category:Freeware Category:Cross-platform web browsers Category:Portable software Category:Software based on WebKit