PhantomJS – Properties


PhantomJS – Web Server Module Properties


”;


PhantomJS uses an embedded web server called mongoose. Right now, PhantomJS cannot connect with any other production webserver. With respect to connection, it can deal with 10 connections at a time and more than 10 requests will be waiting in a queue.

To start a webserver, we need to use the following syntax −

var webserver = require (‘webserver’);

Let us understand the Port property, which is used to listen to the requests that are sent to the webserver.

port

The Port property for a webserver is used to listen to the request that are sent to it.

Syntax

Its syntax is as follows −

var server = require(''webserver'').create();
var listening = server.listen(port, function (request, response) {});

Example

Let us take an example to understand how the port property works.

var webserver = require(''webserver''); 
var server = webserver.create(); 
var service = server.listen(8080,function(request,response){  
}); 
if(service) console.log("server started - http://localhost:" + server.port); 

The above program generates the following output.

server started - http://localhost:8080

Advertisements

”;

Leave a Reply

Your email address will not be published. Required fields are marked *

PhantomJS – Properties


PhantomJS – Webpage Module Properties


”;


PhantomJS provides quite a lot of properties and methods to help us to interact with the contents inside a webpage.

The require(“webpage”).create() command creates a webpage object. We will use this object to manipulate the webpage with the help of properties and methods listed below.

var wpage = require("webpage").create();

The following table has the list of all the webpage properties that we are going to discuss.

S.No Properties & Description
1 canGoBack

This property returns true if there is previous page in the navigation history; if not, false.

2 canGoForward

This property returns true if there is next page in the navigation history; if not, false.

3 clipRect

clipRect is an object with values top, left, width and height and used to take the image capture of the webpage when used by the render() method.

4 Content

This property contains the contents of webpage.

5 cookies

With cookies, you can set /get the cookies available on the URL. It will also give you the cookies available on the URL and the new cookies set on the page.

6 customHeaders

customHeaders specifies additional HTTP request headers that will be send to server for every request issued by the page.

7 Event

It gives long list of events i.e. modifier, keys details.

8 focusedFrameName

Returns the name of the currently focused frame.

9 frameContent

This property gives the content of the frame which is active.

10 frameName

Returns the name of the currently focused frame.

11 framePlainText

This property also gives the contents of the current active frame but only contents without any html tags.

12 frameTitle

Gives the title of the active frame.

13 frameUrl

This property will give the url of the currently focused frame.

14 framesCount

Gives the count of the frames present on the page.

15 framesName

Gives array of frame names.

16 libraryPath

This property has the path, which is used by page.inectJs method.

17 navigationLocked

This property defines whether navigation of the page is allowed or not. If true it will be on current page url and clicking on page to go to next page will not be allowed.

18 offlineStoragePath

This property gives the path where the data is stored using window.localStorage.The path can be changed using –local-storage-path from command line.

19 offlineStorageQuota

This property defines the maximum amount of data you can store in window.localStorage.The value is 5242880 bytes which is 5MB.This value can overwritten at command line using the following command –localstorage-quota = size over here.

20 ownsPages

ownsPages returns true or false if the page opened by the webpage is a child of the webpage.

21 pagesWindowName

PagesWindowName will give the names of the windows open using window.open

22 pages

The pages property will you give array of pages opened in a page using window.open. If the page is closed in url you referring the page will not be considered.

23 paperSize

This property gives the size ie dimensions of the webpage when needs to be used to convert the webpage in a pdf format.paperSize contains the dimensions required in an object.

24 plaintext

This property also gives the contents of the current active frame but only contents without any html tags.

25 scrollPosition

This contains object indicating the scroll position. It gives left and top.

26 settings

This property will give the settings of the webpage when page.open method is used. Once the page is loaded the changes in settings properties will not create any impact.

27 title

This property will give you the title of the page you are reading.

28 url

This property will give the page url.

29 viewportSize

This property allows to change the size of the window display. It contains width and height, which you can read or change it as per the needs.

30 windowName

Gives the name of the window.

31 zoomFactor

This property specifies the zoom factor for render and renderBase64 methods. It helps to zoom a page and take a screen capture if required.

Advertisements

”;

Leave a Reply

Your email address will not be published. Required fields are marked *