Skip to content
This repository has been archived by the owner on Sep 11, 2022. It is now read-only.

Latest commit

 

History

History
197 lines (141 loc) · 6.53 KB

phantom.md

File metadata and controls

197 lines (141 loc) · 6.53 KB

Phantom

The Phantom Class contains all the functionality that would otherwise be in the global phantom-object in PhantomJS.

All functions that are part of PhantomJS' API include the documentation from their webpage. Comments outside of the PhantomJS docs will include a Developer Note-tag. In addition, all functions that can be found in the API also have links to the respective pages. All functions are listed in alphabetical order

The full PhantomJS documentation for the Phantom object can be found here

Kind: global class

phantom.addCookie(cookie) ⇒ Promise(Boolean)

addCookie

Add a Cookie to the CookieJar.

Cookie object is as follows:

{
  domain  : string,
  value   : string, // required
  name    : string, // required
  httponly: boolean,
  path    : string,
  secure  : boolean
}

Kind: instance method of Phantom
Returns: Promise(Boolean) - Whether successful or not

Param Type
cookie Object

phantom.clearCookies() ⇒ Promise(Boolean)

clearCookie

Delete all Cookies in the CookieJar

Kind: instance method of Phantom

phantom.createPage() ⇒ Promise(Page)

Creates a Page. This is equivalent to doing webpage.create() in PhantomJS

See webpage docs for how to use the Page object

Kind: instance method of Phantom

phantom.deleteCookie(cookieName) ⇒ Promise(Boolean)

deleteCookie

Delete any Cookies in the CookieJar with a 'name' property matching cookieName. Returns true if successful, otherwise false

Kind: instance method of Phantom
Returns: Promise(Boolean) - Whether successful or not

Param Type
cookieName String

phantom.exit() ⇒ Promise()

exit

Exits the phantom process, will lock down all other functions

Kind: instance method of Phantom

phantom.get(property) ⇒ Promise(Value)

node-phantom-simple specific

Returns a property, the following can be retrieved:

  • cookies
  • cookiesEnabled
  • libraryPath
  • scriptName deprecated
  • args deprecated
  • version

Kind: instance method of Phantom

Param Type
property String

phantom.getCookie(cookieName) ⇒ Promise(Undefined) | Promise(object)

Wrapper specific

Retrieves a cookie by name. Does this by retrieving the cookie array and finding the cookie that has the cookieName.

Kind: instance method of Phantom
Returns: Promise(Undefined) | Promise(object) - Undefined if not found, otherwise cookie

Param Type Description
cookieName String name of the cookie (cannot contain spaces)

phantom.hasExited() ⇒ Boolean

Wrapper specific

Returns true if phantom.exit() has been run.

Kind: instance method of Phantom

phantom.injectJs(filename) ⇒ Promise(Boolean)

injectJs

Injects external script code from the specified file into the Phantom outer space. If the file cannot be found in the current directory, libraryPath is used for additional look up. This function returns true if injection is successful, otherwise it returns false.

Kind: instance method of Phantom
Returns: Promise(Boolean) - true if successful, false if not

Param Type
filename String

phantom.on()

node-phantom-simple specific

As the browser instance is a 'spawn' object, this can be used to set certain event handlers on, such as 'error'. All arguments are sent to the node-phantom-simples on handler

Kind: instance method of Phantom

phantom.set(property) ⇒ Promise(Boolean)

node-phantom-simple specific

Sets a property to a set value. The following can be changed:

  • cookies
  • cookiesEnabled
  • libraryPath

Kind: instance method of Phantom

Param Type
property String

phantom.setProxy(ip, port, proxyType, username, password) ⇒ Promise()

Developer Note: Sets a proxy by different settings. This function is undocumented and is not in the API-documentation of PhantomJS.

Kind: instance method of Phantom

Param Type Description
ip String ip to the proxy
port String Port of the proxy
proxyType String http, sock5 or non
username String username of the proxy
password String password of the proxy