For faster navigation, this Iframe is preloading the Wikiwand page for PhantomJS.

PhantomJS

PhantomJS
開發者Ariya Hidayat
首次发布2011年1月17日,​13年前​(2011-01-17
最终版本
  • 2.1.1 (2016年1月24日)[1]
編輯維基數據鏈接
源代码库 編輯維基數據鏈接
编程语言C++JavaScriptC
类型無頭瀏覽器
许可协议BSD许可证[2]
网站phantomjs.org/ 编辑维基数据

PhantomJS是一种已停止開發的无头浏览器,用于自动化网页交互。PhantomJS 提供了一个JavaScript API,支持自动模擬鼠標、屏幕截图、用户行为和断言,使其成为用于在无头系统(如持续集成环境)中运行基于浏览器的单元测试的常用工具。PhantomJS 基于WebKit,使其成为类似于SafariGoogle Chrome(在其WebKit分支变为Blink之前)的浏览环境。它是在BSD许可证下发布的开源软件

历史

[编辑]

PhantomJS 经过几年的开发,于 2011年1月23日由 Ariya Hidayat 发布[4]第一次公開提交是在 2011 年。 [5]

PhantomJS 的常用标志是黑色背景上的荧光蓝色幽灵。这是指缺少图形用户界面或浏览器主体,使 PhantomJS 用户看起来像鬼。

2018年3月,由于缺乏积极贡献,PhantomJS 的开发暂停。[6]

用法

[编辑]

PhantomJS的JavaScript API 可用于打开网页、截屏、执行用户操作以及在页面上下文中运行注入的 JavaScript。例如,以下代码将打开英文維基百科,并在加载时将屏幕截图保存到文件并退出。

console.log('正在載入頁面');
var page = require('webpage').create();
var url = 'http://en.wikipedia.org/';
page.open(url, function (status) {
  console.log('頁面已載入');
  page.render('wikipedia.org.png');
  phantom.exit();
});

生态系统

[编辑]

PhantomJS 的影響力之大,以至于类似的项目都采用 API 作为与无头浏览器交互的标准方式。 SlimerJS 提供了一个类似 PhantomJS 的 API,但是基于MozillaGecko 浏览器引擎而不是 WebKit。[7]類似的專案trifleJS 针对Internet ExplorerMSHTML引擎。[8]

PhantomJS 发布后不久,Nicolas Perriault 编写了 CasperJS,这是一套基于 PhantomJS 的库,可扩展其作为自动网页测试客户端的功能,允许用户利用 PhantomJS 创建行为驱动开发测试。CasperJS 的最终版本在2017年發佈。[9]

雅虎开发了一个利用 PhantomJS 收集网站性能指标的 YSlow 版本。[10]

用户

[编辑]

几家著名的公司已经使用了 PhantomJS。

  • Twitter从 2015 年开始使用QUnit和 PhantomJS 进行单元测试。[11]
  • 自 2011 年起,LinkedIn使用基于 PhantomJS 的工具进行性能测试。[12]
  • 自 2014 年起,Netflix使用 Sketchy(一个使用 PhantomJS 构建的无头浏览器)来了解其網頁的行爲而无需访问该网站。[13]
  • 自 2012 年起,时代华纳有线电视公司将 PhantomJS 与CoffeeScript 、 Jasmine和JUnit XML 一起用于Jenkins持续集成。[14]

参见

[编辑]

参考來源

[编辑]
  1. ^ Release 2.1.1. 2016年1月24日 [2018年7月22日]. 
  2. ^ phantomjs/LICENSE.BSD at master · ariya/phantomjs. GitHub. [2022-03-24]. (原始内容存档于2022-04-21) (英语). 
  3. ^ Releases · ariya/phantomjs. GitHub. [2017-04-21]. (原始内容存档于2022-04-09). 
  4. ^ don't code today what you can't debug tomorrow. ariya.blogspot.com. [2015-07-20]. (原始内容存档于2015-07-23). 
  5. ^ ariya/phantomjs. GitHub. [2015-07-20]. (原始内容存档于2022-04-21). 
  6. ^ Archiving the project: suspending the development. ariya/phantomjs. Github. 2018-03-03 [2022-03-24]. (原始内容存档于2022-05-12). 
  7. ^ Laurent Jouanneau. FaQ - SlimerJS. slimerjs.org. [2015-07-20]. (原始内容存档于2022-03-31). 
  8. ^ trifleJS. [2015-07-20]. (原始内容存档于2022-04-01). 
  9. ^ CasperJS on GitHub. GitHub. [2021-04-11]. (原始内容存档于2022-03-24). 
  10. ^ Marcel Duran. YSlow - Official Open Source Project Website. yslow.org. [2015-07-20]. (原始内容存档于2022-04-27). 
  11. ^ Leo Lanese on Twitter. Twitter. [2015-07-20]. (原始内容存档于2022-04-08). 
  12. ^ phegaro. LinkedIn Mobile: How do we do it?. SlideShare. [2015-07-20]. (原始内容存档于2021-06-16). 
  13. ^ Michael Mimoso. Netflix Open Source Security Tools Solve Range of Challenges. threatpost.com. [2015-07-20]. (原始内容存档于2021-06-12). 
  14. ^ one year of wandering headlessly. ofilabs.com. [2015-07-20]. (原始内容存档于2015-07-22). 
{{bottomLinkPreText}} {{bottomLinkText}}
PhantomJS
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?