lib/phantom/modules/selectorDetect.js
function snapshot (options, detector, filter) {
  filter = filter || function(content) { return content; };

  console.log("Creating snapshot for "+options.url+"...");

  // https://github.com/ariya/phantomjs/issues/10930
  page.customHeaders = {
    "Accept-Encoding": "identity"
  };

  // add optional verbose output
  if (options.verbose) {
    verbose(page);
  }

  // create the snapshot
  page.open(options.url, {
    resourceTimeout: options.timeout - 300 // a little space to report problems.
  }, function (status) {
    if (status !== "success") {
      // if phantomJS could not load the page, so end right now
      globals.exit(2, "Unable to load page " + options.url);
    } else {
      // phantomJS loaded the page, so wait for it to be ready
      waitFor(

        // The test to determine readiness
        function () {
          return page.evaluate(detector, {
            selector: options.selector,
            url: options.url
          });
        },

        // The onReady callback
        function (time) {
          fs.write(options.outputFile, filter(page.content), "w");
          globals.exit(0, "snapshot for "+options.url+" finished in "+time+" ms\n  written to "+options.outputFile);
        },

        // The onTimeout callback
        function () {
          globals.exit(1, "timed out waiting for "+options.selector+" to become visible for "+options.url);
        },

        options.timeout,
        options.checkInterval

      );
    }
  });
}
function snapshot (options, detector, filter) {
  filter = filter || function(content) { return content; };

  console.log("Creating snapshot for "+options.url+"...");

  // https://github.com/ariya/phantomjs/issues/10930
  page.customHeaders = {
    "Accept-Encoding": "identity"
  };

  // add optional verbose output
  if (options.verbose) {
    verbose(page);
  }

  // create the snapshot
  page.open(options.url, {
    resourceTimeout: options.timeout - 300 // a little space to report problems.
  }, function (status) {
    if (status !== "success") {
      // if phantomJS could not load the page, so end right now
      globals.exit(2, "Unable to load page " + options.url);
    } else {
      // phantomJS loaded the page, so wait for it to be ready
      waitFor(

        // The test to determine readiness
        function () {
          return page.evaluate(detector, {
            selector: options.selector,
            url: options.url
          });
        },

        // The onReady callback
        function (time) {
          fs.write(options.outputFile, filter(page.content), "w");
          globals.exit(0, "snapshot for "+options.url+" finished in "+time+" ms\n  written to "+options.outputFile);
        },

        // The onTimeout callback
        function () {
          globals.exit(1, "timed out waiting for "+options.selector+" to become visible for "+options.url);
        },

        options.timeout,
        options.checkInterval

      );
    }
  });
}
snapshot

Opens the page and waits for the selector to become visible. Then takes the html snapshot.
Applies an optional output filter to the html content.