Socket
Socket
Sign inDemoInstall

phantom

Package Overview
Dependencies
Maintainers
1
Versions
108
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

phantom - npm Package Compare versions

Comparing version 4.0.11 to 4.0.12

124

lib/phantom.js

@@ -17,2 +17,3 @@ 'use strict';Object.defineProperty(exports, "__esModule", { value: true });

const defaultLogLevel = process.env.DEBUG === 'true' ? 'debug' : 'info';
const defaultPathToShim = _path2.default.normalize(`${__dirname}/shim/index.js`);
const NOOP = 'NOOP';

@@ -46,11 +47,19 @@

/**
* Creates a new instance of Phantom
*
* @param args command args to pass to phantom process
* @param [phantomPath] path to phantomjs executable
* @param [logger] object containing functions used for logging
* @param [logLevel] log level to apply on the logger (if unset or default)
*/
* Creates a new instance of Phantom
*
* @param args command args to pass to phantom process
* @param [phantomPath] path to phantomjs executable
* @param [logger] object containing functions used for logging
* @param [logLevel] log level to apply on the logger (if unset or default)
*/
// eslint-disable-next-line
constructor(args = [], { phantomPath = _phantomjsPrebuilt2.default.path, logLevel = defaultLogLevel, logger = createLogger({ logLevel }) } = {}) {
constructor(
args = [],
{
phantomPath = _phantomjsPrebuilt2.default.path,
shimPath = defaultPathToShim,
logLevel = defaultLogLevel,
logger = createLogger({ logLevel }) } =
{})
{
if (!Array.isArray(args)) {

@@ -65,2 +74,7 @@ throw new Error('Unexpected type of parameters. Expecting args to be array.');

if (typeof shimPath !== 'string') {
throw new Error('Path to shim file was not found. ' +
'Are you sure you entered the path correctly? Exiting.');
}
if (!logger.info && !logger.debug && !logger.error && !logger.warn) {

@@ -70,13 +84,15 @@ throw new Error('logger must be a valid object.');

// eslint-disable-next-line no-unused-vars
const noop = (...msg) => undefined;
this.logger = {
info: logger.info ? (...msg) => logger.info(...msg) : () => undefined,
debug: logger.debug ? (...msg) => logger.debug(...msg) : () => undefined,
error: logger.error ? (...msg) => logger.error(...msg) : () => undefined,
warn: logger.warn ? (...msg) => logger.warn(...msg) : () => undefined };
info: logger.info ? (...msg) => logger.info(...msg) : noop,
debug: logger.debug ? (...msg) => logger.debug(...msg) : noop,
error: logger.error ? (...msg) => logger.error(...msg) : noop,
warn: logger.warn ? (...msg) => logger.warn(...msg) : noop };
const pathToShim = _path2.default.normalize(`${__dirname}/shim/index.js`);
this.logger.debug(`Starting ${phantomPath} ${args.concat([pathToShim]).join(' ')}`);
this.logger.debug(`Starting ${phantomPath} ${args.concat([shimPath]).join(' ')}`);
this.process = (0, _child_process.spawn)(phantomPath, args.concat([pathToShim]), { env: process.env });
this.process = (0, _child_process.spawn)(phantomPath, args.concat([shimPath]), { env: process.env });
this.process.stdin.setDefaultEncoding('utf-8');

@@ -167,5 +183,5 @@

/**
* Returns a new instance of Promise which resolves to a {@link Page}.
* @returns {Promise.<Page>}
*/
* Returns a new instance of Promise which resolves to a {@link Page}.
* @returns {Promise.<Page>}
*/
createPage() {

@@ -190,5 +206,5 @@ const { logger } = this;

/**
* Creates a special object that can be used for returning data back from PhantomJS
* @returns {OutObject}
*/
* Creates a special object that can be used for returning data back from PhantomJS
* @returns {OutObject}
*/
createOutObject() {

@@ -199,5 +215,5 @@ return new _out_object2.default(this);

/**
* Used for creating a callback in phantomjs for content header and footer
* @param obj
*/
* Used for creating a callback in phantomjs for content header and footer
* @param obj
*/
// eslint-disable-next-line class-methods-use-this

@@ -214,6 +230,6 @@ callback(obj) {

/**
* Executes a command object
* @param command the command to run
* @returns {Promise}
*/
* Executes a command object
* @param command the command to run
* @returns {Promise}
*/
executeCommand(command) {

@@ -249,9 +265,9 @@ this.commands.set(command.id, command);

/**
* Executes a command
*
* @param target target object to execute against
* @param name the name of the method execute
* @param args an array of args to pass to the method
* @returns {Promise}
*/
* Executes a command
*
* @param target target object to execute against
* @param name the name of the method execute
* @param args an array of args to pass to the method
* @returns {Promise}
*/
execute(target, name, args = []) {

@@ -262,10 +278,10 @@ return this.executeCommand(new _command2.default(target, name, args));

/**
* Adds an event listener to a target object (currently only works on pages)
*
* @param event the event type
* @param target target object to execute against
* @param runOnPhantom would the callback run in phantomjs or not
* @param callback the event callback
* @param args an array of args to pass to the callback
*/
* Adds an event listener to a target object (currently only works on pages)
*
* @param event the event type
* @param target target object to execute against
* @param runOnPhantom would the callback run in phantomjs or not
* @param callback the event callback
* @param args an array of args to pass to the callback
*/
on(event, target, runOnPhantom, callback, args = []) {

@@ -288,7 +304,7 @@ const eventDescriptor = { type: event };

/**
* Removes an event from a target object
*
* @param event
* @param target
*/
* Removes an event from a target object
*
* @param event
* @param target
*/
off(event, target) {

@@ -316,4 +332,4 @@ const emitter = this.getEmitterForTarget(target);

/**
* Cleans up and end the phantom process
*/
* Cleans up and end the phantom process
*/
exit() {

@@ -329,4 +345,4 @@ clearInterval(this.heartBeatId);

/**
* Clean up and force kill this process
*/
* Clean up and force kill this process
*/
kill(errmsg = 'Phantom process was killed') {

@@ -346,4 +362,4 @@ this.rejectAllCommands(errmsg);

/**
* rejects all commands in this.commands
*/
* rejects all commands in this.commands
*/
rejectAllCommands(msg = 'Phantom exited prematurely') {

@@ -350,0 +366,0 @@ // prevent heartbeat from preventing this from terminating

@@ -6,3 +6,3 @@ {

"homepage": "https://github.com/amir20/phantomjs-node",
"version": "4.0.11",
"version": "4.0.12",
"repository": {

@@ -35,3 +35,3 @@ "type": "git",

"babel-core": "^6.26.0",
"babel-eslint": "^8.0.2",
"babel-eslint": "^8.0.3",
"babel-plugin-transform-es2015-arrow-functions": "^6.22.0",

@@ -44,7 +44,7 @@ "babel-plugin-transform-es2015-template-literals": "^6.22.0",

"del": "^3.0.0",
"eslint": "^4.12.0",
"eslint": "^4.13.1",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-plugin-flowtype": "^2.39.1",
"eslint-plugin-flowtype": "^2.40.1",
"eslint-plugin-import": "^2.8.0",
"flow-bin": "^0.59.0",
"flow-bin": "^0.61.0",
"gulp": "^3.9.1",

@@ -56,5 +56,5 @@ "gulp-babel": "^7.0.0",

"gulp-watch": "^4.3.5",
"jest": "^21.2.1",
"jest-cli": "^21.2.1",
"prettier-eslint": "^8.2.2"
"jest": "^22.0.3",
"jest-cli": "^22.0.3",
"prettier-eslint": "^8.4.0"
},

@@ -61,0 +61,0 @@ "license": "ISC",

@@ -88,2 +88,3 @@ phantom - Fast NodeJS API for PhantomJS

- The phantomjs path to use
- The path to the shim/index.js to use
- A logger object

@@ -97,2 +98,3 @@ - A log level if no logger was specified

phantomPath: '/path/to/phantomjs',
shimPath: '/path/to/shim/index.js',
logger: yourCustomLogger,

@@ -99,0 +101,0 @@ logLevel: 'debug',

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc