{"bugs":{"url":" https://github.com/sheebz/phantom-proxy/issues","mail":"rob.schieber@gmail.com"},"dist":{"shasum":"56fefcc3fb22cf0eff2eaafd239efc47736eff82","tarball":"https://registry.npmjs.org/phantom-proxy/-/phantom-proxy-0.1.16.tgz","integrity":"sha512-wmNkkVEwsaE8+ZfjsRvOp4XZ2BCZhqm+ACe4h0T9VWwuBiZlZ1jcWw1CiSSWUXZK/tz0pspJsxBHvzdHZsBe+A==","signatures":[{"sig":"MEUCIQDdTULoI7iyCMnLAr9UcN7JYq2/3vmwJckCD2MqrZ1vBgIgF2gaYpcwS7LqhO51bIAUn0B+2fNg74HnnnTfo/ShPas=","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### API\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()\nIt is important to call end when you are done using the proxy to terminate the underlying phantomjs process that is being driven.\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  phantomProxy.end();\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\n#### Subscribing to events\n\n```javascript\nphantomProxy = require('phantom-proxy');\nphantomProxy.create({}, function (proxy) {\n    proxy.page.onConsoleMessage = function (event) {\n        console.log(JSON.stringify(event));\n    };\n});\n```\n\n## More documentation and features to come...\n\n## FAQ\n### Why do we need another nodejs runtime for phantom?\nThe short answer is that phantom-proxy has a better implementation.  Other drivers seem to use a side effect of alerts to communicate with phantomjs, which unfortunately is not a good long term solution. Also all the other libraries I have seen do not have a fully implemented the evaluate function - you can't pass additional arguments to the client side function.  This is a big problem and was the main motivation for creating this package.\n\n## Revision History\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":["phantom","driver","node","phantomjs","phantom-node","node-phantom","feature","test","headless","webkit","cucumber"],"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.62","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","form-data":"~0.0.3","underscore":"~1.4.0"},"devDependencies":{"mocha":"~1.5.0","should":"~1.2.0","cucumber":">0.0.0"},"_id":"phantom-proxy@0.1.16","version":"0.1.16"}