{"bugs":{"url":" https://github.com/sheebz/phantom-proxy/issues","mail":"rob.schieber@gmail.com"},"dist":{"shasum":"e4f92adfecbe696766293c1c8a1b5c6c9032078c","tarball":"https://registry.npmjs.org/phantom-proxy/-/phantom-proxy-0.1.8.tgz","integrity":"sha512-jcY6qyEYQzyarHoSCkr7aA3hsHwfwThCVk8DV2W2hZSNw/SGxaGRY9wHtigdmhnsV3L10ZUYLSJFWbC1ZuP0iA==","signatures":[{"sig":"MEUCIFdAL0g6BVeK8H5waJQgyD8Qq/U2YV+OMvuZjVtdbMPpAiEAnAKqD0jmWeHZYd7SCeBuM+fTg0/uKPXx9wSlwCSabXk=","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\nProvides a proxy interface for phantomjs which runs inside of node.  Now you can run phantom and access the full api from within nodejs.\n\n## Overview\nPhantomJs is an incredibly useful tool for functional and unit testing.  Problem is that it runs in its own process which is outside of node, so you are basically out of luck if you want to integrate with phantomjs from within node.  There are some other libraries - phantom-node, node-phantom, that address the same problem.  \n\n\n## Installation\n`npm install phantom-proxy` \n\n## Usage\n### API\n#### phantomProxy object\n##### createProxy(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```javascript\nrequire('phantom-proxy').createProxy({}, function(proxy){\n  var page = proxy.page,\n  phantom = proxy.phantom;\n  \n});\n```\n\n#### phantom Object\nThe phantom object corresponds to the phantom object in the native phantomJs API.\n#### exit(callbackFn)\nTerminates phantom webserver and destroys proxy.\n```javascript\nrequire('phantom-proxy').createProxy({}, 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    phantom.exit(function(){\n      console.log('phantom proxy is now offline');\n    });\n  }); \n});\n```\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```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##### open(url, callbackFn)\nOpens a webpage with url and callback function arguments.\n```javascript\nrequire('phantom-proxy').createProxy({}, 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  \n});\n```\n##### waitForSelector(selector, callbackFn)\nPolls page for presence of selector, executes callback when selector is present.\n```javascript\nrequire('phantom-proxy').createProxy({}, 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    console.log('page now open');\n  });  \n  \n});\n```\n\n##### render(fileName, callbackFn)\nRenders a image of browser.\n```javascript\nrequire('phantom-proxy').createProxy({}, 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    });\n    console.log('page now open');\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```javascript\nphantomProxy = require('phantom-proxy');\nphantomProxy.createProxy({}, function (proxy) {\n    proxy.page.onConsoleMessage = function (event) {\n        console.log(JSON.stringify(event));\n    };\n});\n```\n\n## FAQ\n### Why do we need another nodejs runtime for phantom?\nPhantom-proxy takes a different approach to communicating with phantom than these modules.  Phantom-node passes messages using alerts and express.  While this was an ingenious solution to a difficult problem at the time, better solutions are now available.  As of version 1.4, phantomjs provides an embedded webserver called mongoose which can be used to pass messages.  Phantom-proxy leverages this, which is the fastst and most reliable approach.\n\n\n\n","engines":{"node":">0.6.0"},"private":false,"_npmUser":{"name":"sheebz","email":"rob.schieber@gmail.com"},"keywords":["phantom","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 set of proxy objects for driving  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.8","version":"0.1.8"}