- 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.
- C語言程序設計案例教程
- Twilio Best Practices
- Vue.js 3.0源碼解析(微課視頻版)
- oreilly精品圖書:軟件開發者路線圖叢書(共8冊)
- STM32F0實戰:基于HAL庫開發
- Java應用開發技術實例教程
- Access 2016數據庫管
- JavaScript入門經典
- Python編程從0到1(視頻教學版)
- Mastering openFrameworks:Creative Coding Demystified
- “笨辦法”學C語言
- R數據科學實戰:工具詳解與案例分析
- Python:Deeper Insights into Machine Learning
- Python機器學習算法與應用
- PrimeFaces Blueprints