- PhantomJS Cookbook
- Rob Friesel
- 234字
- 2021-07-16 11:37:57
Inspecting the version at runtime
This recipe will introduce the global phantom
object in PhantomJS and discuss how we can inspect the version at runtime using the version
property.
Getting ready
To run this recipe, we will need a script that accesses phantom.version
. The script in this recipe is available in the downloadable code repository as recipe01.js
under chapter02
. If we run the provided example script, we must change to the root directory for the book's sample code.
How to do it…
Consider the following script:
console.log('PhantomJS'); console.log(' - major version: ' + phantom.version.major); console.log(' - minor version: ' + phantom.version.minor); console.log(' - patch version: ' + phantom.version.patch); phantom.exit();
Given the preceding script, enter the following at the command line:
phantomjs chapter02/recipe01.js
Our output should look like the following:
PhantomJS - major version: 1 - minor version: 9 - patch version: 2
How it works…
Our script operates by accessing the version
object on the global phantom
object and writing its properties (major
, minor
, and patch
) to the console. The build of PhantomJS will have this metadata built in and exposed through phantom.version
as read-only information.
Although our example is a trivial one, knowing the specific PhantomJS version at runtime can be helpful for building flexible scripts/libraries. For example, knowing the version at runtime can help us target preferred APIs while still falling back on older or deprecated ones in the event that those APIs are not available.
- Computer Vision for the Web
- Cassandra Data Modeling and Analysis
- Mastering Predictive Analytics with Python
- Python數據分析從0到1
- UML 基礎與 Rose 建模案例(第3版)
- MySQL從入門到精通(軟件開發視頻大講堂)
- Android項目實戰:手機安全衛士開發案例解析
- Python數據可視化之美:專業圖表繪制指南(全彩)
- 零基礎學C語言(升級版)
- LabVIEW數據采集
- 你真的會寫代碼嗎
- 虛擬現實建模與編程(SketchUp+OSG開發技術)
- Sitecore Cookbook for Developers
- PHP程序設計高級教程
- R語言與網站分析