PhantomJS is a discontinued
headless browser used for automating web page interaction. PhantomJS provides a
JavaScript
JavaScript (), often abbreviated as JS, is a programming language and core technology of the World Wide Web, alongside HTML and CSS. Ninety-nine percent of websites use JavaScript on the client side for webpage behavior.
Web browsers have ...
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
A headless computer is a computer system or device that has been configured to operate without a monitor (the missing "head"), Keyboard (computing), keyboard, and mouse (computing), mouse. A headless system is typically controlled over a network c ...
like a
continuous integration
Continuous integration (CI) is the practice of integrating source code changes frequently and ensuring that the integrated codebase is in a workable state.
Typically, developers Merge (version control), merge changes to an Branching (revisio ...
environment. PhantomJS is based on
WebKit
WebKit is a browser engine primarily used in Apple's Safari web browser, as well as all web browsers on iOS and iPadOS. WebKit is also used by the PlayStation consoles starting with the PS3, the Tizen mobile operating systems, the Amazon K ...
making it a similar browsing environment to
Safari
A safari (; originally ) is an overland journey to observe wildlife, wild animals, especially in East Africa. The so-called big five game, "Big Five" game animals of Africa – lion, African leopard, leopard, rhinoceros, African elephant, elep ...
and
Google Chrome
Google Chrome is a web browser developed by Google. It was first released in 2008 for Microsoft Windows, built with free software components from Apple WebKit and Mozilla Firefox. Versions were later released for Linux, macOS, iOS, iPadOS, an ...
(before Chrome's fork of WebKit evolved into
Blink
Blinking is a bodily function; it is a semi-autonomic rapid closing of the eyelid. A single blink is determined by the forceful closing of the eyelid or inactivation of the levator palpebrae superioris and the activation of the palpebral por ...
). It is
open-source software
Open-source software (OSS) is Software, computer software that is released under a Open-source license, license in which the copyright holder grants users the rights to use, study, change, and Software distribution, distribute the software an ...
released under the
BSD License
BSD licenses are a family of permissive free software licenses, imposing minimal restrictions on the use and distribution of covered software. This is in contrast to copyleft licenses, which have share-alike requirements. The original BSD lic ...
.
History
PhantomJS was released January 23, 2011 by Ariya Hidayat after several years in development.
The first commit to the public project was in 2011.
The logo commonly used to pictorially refer to PhantomJS is a fluorescent blue 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.
In March 2018, the development of PhantomJS was suspended due to lack of active contributions.
Usage
The PhantomJS JavaScript API can be used to open web pages, take screenshots, execute user actions, and run injected JavaScript in the page context. For example, the following code will open Wikipedia and, upon loading, will save a screenshot to a file and exit.
console.log('Loading a web page');
var page = require('webpage').create();
var url = 'http://en.wikipedia.org/';
page.open(url, function (status) );
Ecosystem
PhantomJS became valuable enough that similar projects adopted the API as a standard way of interacting with headless browsers.
SlimerJS provided a PhantomJS-like API, but on top of
Mozilla
Mozilla is a free software community founded in 1998 by members of Netscape. The Mozilla community uses, develops, publishes and supports Mozilla products, thereby promoting free software and open standards. The community is supported institution ...
's
Gecko browser engine rather than WebKit. Similarly, trifleJS targeted the
MSHTML
Trident (also known as MSHTML) is a proprietary browser engine for the Microsoft Windows version of Internet Explorer, developed by Microsoft.
MSHTML debuted with the release of Internet Explorer 4 in 1997. For versions 7 and 8 of Internet Expl ...
engine of
Internet Explorer
Internet Explorer (formerly Microsoft Internet Explorer and Windows Internet Explorer, commonly abbreviated as IE or MSIE) is a deprecation, retired series of graphical user interface, graphical web browsers developed by Microsoft that were u ...
.
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, allowing users to create
BDD tests leveraging PhantomJS. The final release of CasperJS was in 2017.
Yahoo!
Yahoo (, styled yahoo''!'' in its logo) is an American web portal that provides the search engine Yahoo Search and related services including My Yahoo, Yahoo Mail, Yahoo News, Yahoo Finance, Yahoo Sports, y!entertainment, yahoo!life, and its a ...
developed a version of
YSlow that leverages PhantomJS to gather performance metrics for websites.
Users
Several notable companies have used PhantomJS.
*
Twitter
Twitter, officially known as X since 2023, is an American microblogging and social networking service. It is one of the world's largest social media platforms and one of the most-visited websites. Users can share short text messages, image ...
used
QUnit
QUnit is a JavaScript framework for unit testing. Originally developed for testing jQuery, jQuery UI and jQuery Mobile, it is a generic framework for testing any JavaScript code. It supports client-side environments in web browsers, and server ...
and PhantomJS for unit testing as of 2015.
*
LinkedIn
LinkedIn () is an American business and employment-oriented Social networking service, social network. It was launched on May 5, 2003 by Reid Hoffman and Eric Ly. Since December 2016, LinkedIn has been a wholly owned subsidiary of Microsoft. ...
used PhantomJS based tools for performance testing as of 2011.
*
Netflix
Netflix is an American subscription video on-demand over-the-top streaming service. The service primarily distributes original and acquired films and television shows from various genres, and it is available internationally in multiple lang ...
used Sketchy, a headless browser built with PhantomJS, to understand what it's doing without having to visit the site as of 2014.
*
Time Warner Cable
Time Warner Cable Enterprises LLC was an American cable television company. Before it was acquired by Charter Communications on May 18, 2016, it was ranked the second largest cable company in the United States by revenue behind only Comcast, o ...
used PhantomJS with
CoffeeScript
CoffeeScript is a programming language that compiles to JavaScript. It adds syntactic sugar inspired by Ruby, Python, and Haskell in an effort to enhance JavaScript's brevity and readability. Some added features include list comprehension an ...
,
Jasmine
Jasmine (botanical name: ''Jasminum'', pronounced ) is a genus of shrubs and vines in the olive family of Oleaceae. It contains around 200 species native to tropical and warm temperate regions of Eurasia, Africa, and Oceania. Jasmines are wid ...
, and
JUnit
JUnit is a test automation framework for the Java programming language. JUnit is often used for unit testing, and is one of the xUnit frameworks.
JUnit is linked as a JAR at compile-time. The latest version of the framework, JUnit 5, resides ...
XML for
Jenkins continuous integration as of 2012.
See also
*
Headless browser
References
External links
*
GitHub
{{DEFAULTSORT:PhantomJS
C++ software
Web browsers
Cross-platform web browsers
Discontinued software
Software based on WebKit
Software using the BSD license
2011 software