New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

phantom-server

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

phantom-server

Allows you to interact with PhantomJS from NodeJS by hosting it as a server

latest
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

Phantom Server

This project uses the webserver library in PhantomJS to host a simple phantomjs webserver that will run scripts you pass it over http. This allows you to easily run scripts that require the DOM (d3, js enabled web scrapers) from NodeJS.

Example

This is a simple example demonstrating that window will be defined in your evaluate scripts. For a more complex example that uses d3, see examples/d3.

# script.js
/**
 * This is the function that will be run in the page by PhantomJS. It has access
 * anything you would normally have access to in a page.
 */
module.exports = function() {
    return window !== undefined;
};
# index.js
var path = require( 'path' );

var PhantomServer = require( 'phantom-server' ),
    phantomjs_path = require( 'phantomjs-prebuilt' ).path;

var phantom_server = new PhantomServer( phantomjs_path );

phantom_server
    .run( {
        evaluate_scripts: [
            path.join( __dirname, 'script.js' );
        ]
    } )
    .then( function( evaluate_responses ) {
        console.log( evaluate_responses[ 0 ] ); // true
        phantom_server.stop(); // MAKE SURE YOU STOP THE SERVER WHEN YOU ARE DONE
    } );

Keywords

nodejs

FAQs

Package last updated on 06 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts