{"bugs":{"url":" https://github.com/sheebz/phantom-proxy/issues","mail":"rob.schieber@gmail.com"},"dist":{"shasum":"86352288eac26ea69ea2c645ef25329bb4932680","tarball":"https://registry.npmjs.org/phantom-proxy/-/phantom-proxy-0.1.77.tgz","integrity":"sha512-nCDPTdtay/qauWHLcW042CXoqnBPGwWn3jMi1A4zOUPzzM1hUkKdciRmdDqZkXW1lb0QsIv17gow5EnH0pMBcQ==","signatures":[{"sig":"MEUCIQDiP92q2MnVwcJB2sx0O2mUcwDXPQwpuhOTasEdO98DNAIgZY7J9NU0gf9+DA9TJuituaqp1qMoZZ0o5s3JA1P8e6U=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","name":"phantom-proxy","author":{"url":"https://twitter.com/sheebz","name":"Rob Schieber","email":"rob.schieber@gmail.com"},"readme":"# phantom-proxy\n* Allows you to drive [phantomjs](www.phantomjs.org) from [node](www.nodejs.org)\n* Does not rely on alert side effects for communicating with phantomjs\n* Uses Phantom's embedded mongoose web server for communication - more efficient, simpler, faster.\n* Provides a full api - including a parametrized evaluate function - no more hard coded strings\n* Provides additional useful methods such as waitForSelector\n* Can easily integrate with feature testing frameworks such as [cucumber](https://github.com/cucumber/cucumber-js), jasmine, mocha\n\n## Overview\nPhantomJs is an incredibly useful tool for functional and unit testing.  PhantomJs runs in its own process, making it difficult to drive from node.  Phantom-proxy solves this problem, allowing you to fully drive phantomjs from node.\n\n## Installation\n\n`npm install phantom-proxy`\n\n## Usage\n### Examples\nSee the [API](https://github.com/sheebz/phantom-proxy/blob/master/api.md) documentation for more usage information.\n\n#### wait for a specific selector to appear\n```javascript\nvar phantomProxy = require('phantom-proxy');\n\nphantomProxy.create({}, function (proxy) {\n    var page = proxy.page;\n    page.open('http://www.w3.org', function () {\n        page.waitForSelector('body', function () {\n            console.log('body tag present');\n            proxy.end();\n        });\n    });\n\n});\n```\n\n#### render a screenshot\n```javascript\nphantomProxy.create({\"debug\":true}, function (proxy) {\n    proxy.page.open('http://www.w3.org', function (result) {\n        assert.equal(result, true);\n        proxy.page.waitForSelector('body', function (result) {\n            assert.equal(result, true);\n            proxy.page.render('./scratch/scratch.png', function (result) {\n                assert.equal(result, true);\n                proxy.end(function () {\n                  console.log('done');\n                });\n            });\n        }, 1000);\n    });\n});\n\n```\n\n#### subscribe to events - see api docs for complete list\n```javascript\nphantomProxy.create({\"debug\":true}, function (proxy) {\n    self.proxy.page.on('navigationRequested', function (url) {\n      console.log('at %s', url);\n\n      if (url === 'http://www.w3.org') {\n        console.log('at w3.org');\n      }\n      else {\n        console.log('how did we get here?');\n      }\n\n      proxy.end(function () {\n        console.log('done');\n      });\n    });\n\n    proxy.page.open('http://www.w3.org', function (result) {\n      proxy.page.on('alert', function (msg) {\n          if (msg.trim() === 'hello') {\n              console.log('it said hello');\n          }\n\n        proxy.end(function () {\n          console.log('done');\n        });\n      });\n\n\n\n    });\n});\n\n```\n# API Documentation\n## phantomProxy object\n### create([options], callbackFn)\nuse this method to create an instance of the phantom proxy objects.  The return value will be an object with a page proxy and a phantom proxy.  These properties correspond to the phantom and webpage objects on the native phantom API.\n\nWhen this method is called, a new phantomjs process is spawned.  The new phantomjs process creates a mongoose webserver on localhost:1061.  All subsequent communication with phantom occurs via http requests.\n\n#### Options argument (experimental)\nCreate accepts an options object as the first parameter.  This argument is optional.  Properties and their default values are listed below.\n\n```javascript\n\n        var defaultoptions = {\n            'ignoreSslErrors':true,\n            'localToRemoteUrlAccessEnabled':true,\n            'cookiesFile':'cookies.txt',\n            'diskCache':'yes',\n            'loadImages':'yes',\n            'localToRemoteUrlAccess':'no',\n            'maxDiskCache':'50000',\n            'outputEncoding':'utf8',\n            'proxy':'0',\n            'proxyType':'yes',\n            'scriptEncoding':'yes',\n            'webSecurity':'yes',\n            'port':1061\n        };\n```\n\n### end(callbackFn)\nYou should call end on the returned proxy object to ensure that phantomjs is properly shut down.\n\n```javascript\nvar phantomProxy = require('phantom-proxy').create(function(proxy){\n  var page = proxy.page,\n  phantom = proxy.phantom;\n  //do some stuff...\n  //...\n  //call end when done\n  proxy.end(function(){\n    console.log('phantom has exited');\n  });\n});\n```\n\n## phantom Object\nThe phantom object corresponds to the phantom object in the native phantomJs API.\n\n## Page Object\nThe page object corresponds to the webpage object in the native phantomJs API.\n\n### set(propertyName, propertyValue, callbackFn)\nsets property on page object\n\n```javascript\n  //set viewport size for browser window\n  proxy.page.set('viewportSize',\n  { width:320, height:480 }, function (result) {\n      console.log(result.toString().cyan);\n      worldCallback.call(self);\n  });\n```\n\n### open(url, callbackFn)\nOpens a webpage with url and callback function arguments.\n\n```javascript\nvar phantomProxy = require('phantom-proxy').create({}, function(proxy){\n  var page = proxy.page,\n  phantom = proxy.phantom;\n\n  page.open('http://www.w3.org', function(){\n    console.log('page now open');\n\n    //close proxy\n    phantomProxy.end();\n  });\n\n});\n```\n\n### waitForSelector(selector, callbackFn, timeout)\nPolls page for presence of selector, executes callback when selector is present.\n\n```javascript\nvar phantomProxy = require('phantom-proxy').create({}, function(proxy){\n  var page = proxy.page,\n  phantom = proxy.phantom;\n\n  page.open('http://www.w3.org', function(){\n    page.waitForSelector('body', function(){\n      console.log('body tag present');\n\n        //close proxy\n        phantomProxy.end();\n    });\n    console.log('page now open');\n  });\n\n});\n```\n\n### render(fileName, callbackFn)\nRenders a image of browser.\n\n```javascript\nvar phantomProxy = require('phantom-proxy').create({}, function(proxy){\n  var page = proxy.page,\n  phantom = proxy.phantom;\n\n  page.open('http://www.w3.org', function(){\n    page.waitForSelector('body', function(){\n      console.log('body tag present');\n      page.render('myimage.png', function(){\n        console.log('saved my picture!');\n\n        //close proxy\n        phantomProxy.end();\n      });\n    });\n    console.log('page now open');\n  });\n\n});\n```\n\n### renderBase64(type, callbackFn)\nReturns a base64 representation of image.\n\n### evaluate(functionToEvaluate, callbackFn, [arg1, arg2,... argN]\nExecutes functionToEvaluate in phantomJS browser.  Once function executes, callbackFn will be invoked with a result parameter. The Third and sebsequent arguments represent optional parameters which will be passed to the functionToEvaluate function when it is invoked in the browser.\n\n## Events\nThe following events are supported, see [PhantomJs Docs](https://github.com/ariya/phantomjs/wiki/API-Reference) for more information.\n\n<table><thead><th>Event Name</th><th>Notes</th></thead>\n<tbody>\n<tr><td>urlChanged</td><td></td></tr>\n<tr><td>resourceReceived</td><td></td></tr>\n<tr><td>resourceRequested</td><td></td></tr>\n<tr><td>prompt</td><td>Event will fire, but callback will not execute in phantomjs context</td></tr>\n<tr><td>pageCreated</td><td></td></tr>\n<tr><td>navigationRequested</td><td></td></tr>\n<tr><td>loadStarted</td><td></td></tr>\n<tr><td>loadFinished</td><td></td></tr>\n<tr><td>initialized</td><td></td></tr>\n<tr><td>error</td><td></td></tr>\n<tr><td>consoleMessage</td><td></td></tr>\n<tr><td>confirm</td><td>Event will fire, but callback will not execute in phantomjs context</td></tr>\n<tr><td>closing</td><td></td></tr>\n<tr><td>callback</td><td></td></tr>\n<tr><td>alert</td><td></td></tr>\n</tbody>\n</table>\n\n\n#### Subscribing to events\n\n```javascript\nphantomProxy = require('phantom-proxy');\nphantomProxy.create({}, function (proxy) {\n    proxy.page.on('urlChanged', function(){\n      console.log('url changed');\n    });\n});\n```\n\n\n\n\n## Revision History\n* 2012-11-06 - version 0.1.6\n - reworked event communication interface to use socket.io - no longer using filesyste to pass event messages, should help with dropped msgs\n* 2012-11-06 - version 0.1.6\n - reworked event communication interface - no longer using stdoutput to pass event messages\n - reworked process creation and exit logic\n - startup time and event latency are much improved - should run much faster than before\n* 2012-11-03 - version 0.1.3\n  - added callback parameter to end method on proxy.\n  - removed unref call in proxy\n  - added debug option\n* 2012-10-22 - version 0.1.2\n  - breaking - changed the way events are consumed, switched to using nodes emmitter to brodcast events as opposed to invoking instance methods on the object.  To fix issues, use [object].on('eventname') style syntax.\n  - Code clean up\n* 2012-10-17 - version 0.1.16\n   - fixed waitforSelector issue\n* 2012-10-12  - version 0.1.15\n    - fixed a problem w/ waitforSelector fn.\n    - fixed problem where process wasn't shutting down existing server.\n* version 0.1.13\n  - added args property handling for phantom object\n  - added ability to specify port for rpc channel\n  - added timeout on waitforSelector function\n  - added ability to pass cmd line arguments for phantom via options object\n* version 0.1.10\n  - cleaned up and reorganized code\n  - added unit tests\n  - fixed process related issues\n\n","engines":{"node":">0.6.0"},"private":false,"_npmUser":{"name":"sheebz","email":"rob.schieber@gmail.com"},"keywords":["phantomjs","phantom","cucumber","cucumberjs","feature","testing"],"licenses":[{"url":"https://github.com/sheebz/phantom-proxy/blob/master/README.md","type":"MIT"}],"repository":{"url":"https://github.com/sheebz/phantom-proxy","type":"git"},"_npmVersion":"1.1.65","description":"a lightweight proxy that lets you to drive phantomjs from node.","directories":{"lib":"./lib","test":"./test","example":"./example"},"maintainers":[{"name":"sheebz","email":"rob.schieber@gmail.com"}],"dependencies":{"q":"~0.8.8","mime":"~1.2.7","colors":"~0.6.0-1","express":" ~3.0.3","form-data":"~0.0.3","socket.io":"~0.9.11","underscore":"~1.4.0","event-stream":"~3.0.10"},"readmeFilename":"README.md","devDependencies":{"mocha":"~1.5.0","jshint":"latest","should":"~1.2.0","cucumber":">0.0.0"},"_id":"phantom-proxy@0.1.77","version":"0.1.77"}