lib/html-snapshots.js
function worker (input, options, notifier, qcb) {
  var cp,
      customModule,
      snapshotScript = options.snapshotScript,
      phantomjsOptions = Array.isArray(input.phantomjsOptions) ? input.phantomjsOptions : [input.phantomjsOptions];

  // If the outputFile has NOT already been seen by the notifier, process.
  if (!notifier.known(input.outputFile)) {

    // map snapshotScript object script to a real path
    if (_.isObject(options.snapshotScript)) {
      snapshotScript = path.join(__dirname, phantomDir, options.snapshotScript.script) + ".js";
      customModule = options.snapshotScript.module;
    }

    cp = spawn(
      options.phantomjs,
      phantomjsOptions.concat([
        snapshotScript,
        input.outputFile,
        input.url,
        input.selector,
        input.timeout,
        input.checkInterval,
        input.useJQuery,
        input.verbose,
        customModule
      ]), { cwd: process.cwd(), stdio: "inherit", detached: true }
    );

    cp.on("error", function (e) {
      notifier.remove(input.outputFile);
      notifier.setError(e);
      console.error(e);
      qcb(e);
    });

    cp.on("exit", function (code) {
      qcb(code);
    });

    // start counting
    notifier.add(input.outputFile, input.timeout);
  }
  else {
    // The input.outputFile is being or has been processed this run.
    qcb(0);
  }
}
function worker (input, options, notifier, qcb) {
  var cp,
      customModule,
      snapshotScript = options.snapshotScript,
      phantomjsOptions = Array.isArray(input.phantomjsOptions) ? input.phantomjsOptions : [input.phantomjsOptions];

  // If the outputFile has NOT already been seen by the notifier, process.
  if (!notifier.known(input.outputFile)) {

    // map snapshotScript object script to a real path
    if (_.isObject(options.snapshotScript)) {
      snapshotScript = path.join(__dirname, phantomDir, options.snapshotScript.script) + ".js";
      customModule = options.snapshotScript.module;
    }

    cp = spawn(
      options.phantomjs,
      phantomjsOptions.concat([
        snapshotScript,
        input.outputFile,
        input.url,
        input.selector,
        input.timeout,
        input.checkInterval,
        input.useJQuery,
        input.verbose,
        customModule
      ]), { cwd: process.cwd(), stdio: "inherit", detached: true }
    );

    cp.on("error", function (e) {
      notifier.remove(input.outputFile);
      notifier.setError(e);
      console.error(e);
      qcb(e);
    });

    cp.on("exit", function (code) {
      qcb(code);
    });

    // start counting
    notifier.add(input.outputFile, input.timeout);
  }
  else {
    // The input.outputFile is being or has been processed this run.
    qcb(0);
  }
}
The worker task that launches phantomjs.

@param {Object} input - An input object from an input generator.
@param {Array} input.phantomjsOptions - Actual Phantomjs options.
@param {String} input.outputFile - The output file that the html is written to.
@param {String} input.url - The url to get the html from.
@param {String} input.selector - The selector to wait for.
@param {String} input.timeout - The phantomjs timeout.
@param {String} input.checkInterval - The interval to poll for results.
@param {Boolean} input.useJQuery - True if selector is jquery selector.
@param {Boolean} input.verbose - True if verbose output is desired.
@param {Object} options - Input options.
@param {Object} options.snapshotScript - Snapshot script options.
@param {String} options.snapshotScript.script - Snapshot script name.
@param {String} options.snapshotScript.module - Snapshot script module.
@param {String} options.phantomjs - Full path to the Phantomjs exe.
@param {Object} notifier - The async Notifier instance for this run.
@param {Function} notifier.remove - Remove an outputFile from notifier.
@param {Function} notifier.setError - Set an error on the notifier.
@param {Function} notifier.add - Add a file, timeout to the notifier.
@param {Function} notifier.known - Check if a file is or has been processed.
@param {Function} qcb - async.queue callback function.