{"bugs":{"url":" https://github.com/sheebz/phantom-proxy/issues","mail":"rob.schieber@gmail.com"},"dist":{"shasum":"c18e1308bcb89e169b7e8825055a295c5837b952","tarball":"https://registry.npmjs.org/phantom-proxy/-/phantom-proxy-0.1.10.tgz","integrity":"sha512-UccPL6+FJ5xJ4VAN8drnfPLWTWQXgS0fXBfiPw72HOKWWWt80dVBVeRrp2ZUYeBYvPdXGTNCbWa2BnqfkBpiaw==","signatures":[{"sig":"MEQCIDdfrvfJ9cFZY/doHD0o1I0p8VjZ2wIBRllH3O2gse7TAiAP4o32aZzdZSYIJnKh976CoNc8Dcrgy3aNUtOu8+YRYA==","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 or communicating with phantomjs\n* Uses Phantom's embedded web server for communication\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```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\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##### 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}).end();\n```\n##### waitForSelector(selector, callbackFn)\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}).end();\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## 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","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 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.10","version":"0.1.10"}