{"id":15493451,"url":"https://github.com/sinclairzx81/phantom-network-service","last_synced_at":"2025-04-27T19:32:33.287Z","repository":{"id":12905964,"uuid":"15583201","full_name":"sinclairzx81/phantom-network-service","owner":"sinclairzx81","description":"run phantomjs as a network service","archived":false,"fork":false,"pushed_at":"2014-01-04T07:55:51.000Z","size":529,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-19T11:12:05.047Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sinclairzx81.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-01-02T12:33:58.000Z","updated_at":"2022-09-16T00:30:26.000Z","dependencies_parsed_at":"2022-09-07T17:22:39.254Z","dependency_job_id":null,"html_url":"https://github.com/sinclairzx81/phantom-network-service","commit_stats":null,"previous_names":["sinclairzx81/phantom.net"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinclairzx81%2Fphantom-network-service","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinclairzx81%2Fphantom-network-service/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinclairzx81%2Fphantom-network-service/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinclairzx81%2Fphantom-network-service/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sinclairzx81","download_url":"https://codeload.github.com/sinclairzx81/phantom-network-service/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251196004,"owners_count":21550886,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-02T08:06:47.265Z","updated_at":"2025-04-27T19:32:32.932Z","avatar_url":"https://github.com/sinclairzx81.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿## phantom.net\n\nFor nodejs developers wanting to run [phantomjs](http://phantomjs.org/) as a network service. Includes both server and client library.\n\n#### server\n\nstart a phantom.net service on port 5000.\n\n```javascript\n\nvar phantom = require('phantom.net')\n\nvar server = new phantom.Server(5000)\n```\n\n#### client\n\nconnect to service and render web page as pdf. \n\n```javascript\nvar phantom = require('phantom.net')\n\nvar client = new phantom.Client('http://localhost:5000')\n\nvar parameter = {url: 'http://google.com', mime: 'application/pdf'}\n\nclient.render(parameter, function(readstream) {\n\t\n\t// do something with the stream.\n})\n```\n\n### install\n\n\tnpm install phantom.net\n\nnote: phantomjs needs to be installed on the server machine, and set up as a PATH environment variable.\n\n### contents\n\n* [overview](#overview)\n* [render](#render)\n* [waiting](#waiting)\n* [example](#example)\n* [windows performance](#windows_performance)\n\n\u003ca name=\"overview\" /\u003e\n### overview\n\nphantom.net was written specifically for developers looking to expose phantomjs as a network service. The library allows developers to\nquickly host phantomjs as a http accessible endpoint, and pass it urls and content to render. phantom.net will respond with readable streams. \nUseful for writing results to disk, or back out as http response.\n\n\u003ca name=\"render\" /\u003e\n### render\n\n```javascript\nvar phantom = require('phantom.net')\n\nvar client = new phantom.Client('http://localhost:5000')\n\nvar parameter = {url: 'http://google.com', mime: 'application/pdf'}\n\nclient.render(parameter, function(readstream) {\n\t\n\tvar writestream = require('fs').createWriteStream('output.pdf')\t\n\n\treadstream.pipe(writestream)\n})\n```\n\nThe client render() method accepts a single parameter which is passed to phantomjs for rendering. Below is the parameter definition. When passing\nthis parameter, either url or content must be set. The mime is required, and can be either 'application/pdf', image/jpg', 'image/png' or 'image/gif'\n\nnote: for more details on the following properties, see [here](https://github.com/ariya/phantomjs/wiki/API-Reference-WebPage#properties-list).\n\n```typescript\ninterface Parameter {\n    \n    content?   : string\n\t\n    url?       : string \n        \n    mime       : string \n\n\twait?      : number\n\t\n    viewportSize? : { \n        \n        width   : number \n    \n        height  : number \n    }\n    \n    paperSize? : {\n        \n        width?      : number\n\n        height?     : number\n\n        border?     : string\n\n        format?     : string\n\n        orientation?: string\n    }\n    \n    zoomFactor?  : number\n\n    clipRect? : { \n\n        top   : number\n\n        left  : number \n\n        width : number\n\n        height: number \n    }\n}\n```\n\u003ca name=\"waiting\" /\u003e\n### waiting\n\nBy default, phantom.net will wait 200ms for a page to render. A client can modify this value to increase the allowed for the page\nto load. The following will wait 2 seconds.\n\n```javascript\nvar phantom = require('phantom.net')\n\nvar client = new phantom.Client('http://localhost:5000')\n\nclient.render({url: 'http://google.com', mime: 'application/pdf', wait: 2000}, function(readstream) {\n\t\n})\n```\n\nBy default, the phantom.net server will put limits on waiting (the default is 4 seconds), however you can override the maximum \nwait as follows...\n\n```javascript\n\nvar phantom = require('phantom.net')\n\nvar server = new phantom.Server(5000, {maximum_wait: 10000})\n\n```\n\n\u003ca name=\"example\" /\u003e\n### example\nThe following example demonstrates setting up both a phantom.net server (on port 5001) and phantom.net client within the same process. \nWe also create a basic nodejs http server (on port 5000) to output the stream returned from phantom.net. \n\n```javascript\n\nvar phantom = require('phantom.net')\n\nvar server  = new phantom.Server(5001)\n\nvar client  = new phantom.Client(\"http://localhost:5001\")\n\nrequire('http').createServer(function(req, res) {\n\t\n\tvar parameter = {url: 'http://google.com', \n\t\t\t\t\t mime: 'application/pdf', \n\t\t\t\t\t viewportSize: { width: 1600, height: 1200 } }\n\t\n\tclient.render(parameter, function(errors, stream) {\n\t\t\n\t\tres.writeHead(200, {'Content-Type' : parameter.mime})\n\t\t\n\t\tstream.pipe(res)\n\t})\n\n}).listen(5000)\n\nconsole.log('server listening on port 5000')\n\n```\n\u003ca name=\"windows_performance\" /\u003e\n### windows performance\n\nIf running the server on a windows machine, rendering may take a considerable amount of time. If this is a issue, \nyou can speed things up unchecking 'automatically detect settings' in internet explorers LAN settings, as follows...\n\n* open up internet explorer.\n* options \u003e internet options \u003e connections (tab).\n* uncheck 'automatically detect settings'.\n* click ok.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsinclairzx81%2Fphantom-network-service","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsinclairzx81%2Fphantom-network-service","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsinclairzx81%2Fphantom-network-service/lists"}