Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 3 commits
  • 3 files changed
  • 0 comments
  • 1 contributor
Jul 10, 2012
Seth McLaughlin Ignoring node_modules 2bd1aea
Jul 11, 2012
Seth McLaughlin This patch allows the user to specify where to find the phantomjs
executable, rather than forcing the use of the 'phantomjs' executable
which is in the path.

For example, let's say you have two versions of phantomjs installed at
these locations:

`/home/user/tools/phantomjs/v1.3/bin/phantomjs`
`/home/user/tools/phantomjs/v1.6/bin/phantomjs`

You can choose whether you want to use version 1.3 or 1.6 when calling
phantom.create() with a new, optional, parameter:

```javascript
  phantom.create(cb, '/home/user/tools/phantomjs/v1.6/bin/phantomjs')
```

If this parameter is not specified, then a default of 'phantomjs' will
be used (which will just use whichever phantomjs binary is in your
path).

__Example usage__
```javascript
// using the new parameter
var pathToPhantomJsBinary = '/home/user/tools/phantomjs/v1.6/bin/phantomjs';

phantom.create(function(ph) {
  return ph.createPage(function(page) {
    return page.open(loadUrl, function(status) {
      return page.evaluate((function() {
        return document.title;
      }), function(result) {
        return ph.exit();
      });
    });
  });
}, pathToPhantomJsBinary);

// default behavior still works
phantom.create(function(ph) {
  return ph.createPage(function(page) {
    return page.open(loadUrl, function(status) {
      return page.evaluate((function() {
        return document.title;
      }), function(result) {
        return ph.exit();
      });
    });
  });
});
```
68afdd6
Seth McLaughlin Removing console.log() statement which was being used for debugging 6f482ad
3  .gitignore
... ...
@@ -0,0 +1,3 @@
  1
+node_modules/
  2
+*.swo
  3
+*.swp
14  phantom.coffee
@@ -3,8 +3,8 @@ express = require 'express'
3 3
 child   = require 'child_process'
4 4
 
5 5
 phanta = []
6  
-startPhantomProcess = (port, args) ->
7  
-  ps = child.spawn 'phantomjs', args.concat [__dirname+'/shim.js', port]
  6
+startPhantomProcess = (port, args, binaryPath) ->
  7
+  ps = child.spawn binaryPath, args.concat [__dirname+'/shim.js', port]
8 8
 
9 9
   ps.stdout.on 'data', (data) -> console.log "phantom stdout: #{data}"
10 10
   ps.stderr.on 'data', (data) -> 
@@ -27,18 +27,19 @@ wrap = (ph) ->
27 27
 
28 28
 
29 29
 
30  
-module.exports = 
31  
-  create: (args..., cb) ->
  30
+module.exports =
  31
+  create: (args..., cb, binaryPath) ->
32 32
     app = express.createServer()
33 33
     app.use express.static __dirname
34  
-    
35 34
     appServer = app.listen()
36 35
 
37 36
     server = dnode()
38 37
 
39 38
     phantom = null
40 39
 
41  
-    ps = startPhantomProcess appServer.address().port, args
  40
+    binaryPath = binaryPath || 'phantomjs'
  41
+
  42
+    ps = startPhantomProcess appServer.address().port, args, binaryPath
42 43
 
43 44
     ps.on 'exit', (code) ->
44 45
       appServer.close()
@@ -52,6 +53,7 @@ module.exports =
52 53
       phantom = conn.remote
53 54
       wrap phantom
54 55
       phanta.push phantom
  56
+      phantom.__binaryPath = binaryPath
55 57
       cb? phantom
56 58
 
57 59
 
25  phantom.js
... ...
@@ -1,6 +1,7 @@
  1
+// Generated by CoffeeScript 1.3.3
1 2
 (function() {
2 3
   var child, dnode, express, phanta, startPhantomProcess, wrap,
3  
-    __slice = Array.prototype.slice;
  4
+    __slice = [].slice;
4 5
 
5 6
   dnode = require('dnode');
6 7
 
@@ -10,14 +11,16 @@
10 11
 
11 12
   phanta = [];
12 13
 
13  
-  startPhantomProcess = function(port, args) {
  14
+  startPhantomProcess = function(port, args, binaryPath) {
14 15
     var ps;
15  
-    ps = child.spawn('phantomjs', args.concat([__dirname + '/shim.js', port]));
  16
+    ps = child.spawn(binaryPath, args.concat([__dirname + '/shim.js', port]));
16 17
     ps.stdout.on('data', function(data) {
17 18
       return console.log("phantom stdout: " + data);
18 19
     });
19 20
     ps.stderr.on('data', function(data) {
20  
-      if (data.toString('utf8').match(/No such method.*socketSentData/)) return;
  21
+      if (data.toString('utf8').match(/No such method.*socketSentData/)) {
  22
+        return;
  23
+      }
21 24
       return console.warn("phantom stderr: " + data);
22 25
     });
23 26
     return ps;
@@ -48,14 +51,15 @@
48 51
 
49 52
   module.exports = {
50 53
     create: function() {
51  
-      var app, appServer, args, cb, io, phantom, ps, server, _i;
52  
-      args = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), cb = arguments[_i++];
  54
+      var app, appServer, args, binaryPath, cb, io, phantom, ps, server, _i;
  55
+      args = 3 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 2) : (_i = 0, []), cb = arguments[_i++], binaryPath = arguments[_i++];
53 56
       app = express.createServer();
54  
-      app.use(express.static(__dirname));
  57
+      app.use(express["static"](__dirname));
55 58
       appServer = app.listen();
56 59
       server = dnode();
57 60
       phantom = null;
58  
-      ps = startPhantomProcess(appServer.address().port, args);
  61
+      binaryPath = binaryPath || 'phantomjs';
  62
+      ps = startPhantomProcess(appServer.address().port, args, binaryPath);
59 63
       ps.on('exit', function(code) {
60 64
         var p;
61 65
         appServer.close();
@@ -64,7 +68,9 @@
64 68
           _results = [];
65 69
           for (_j = 0, _len = phanta.length; _j < _len; _j++) {
66 70
             p = phanta[_j];
67  
-            if (p !== phantom) _results.push(p);
  71
+            if (p !== phantom) {
  72
+              _results.push(p);
  73
+            }
68 74
           }
69 75
           return _results;
70 76
         })();
@@ -79,6 +85,7 @@
79 85
         phantom = conn.remote;
80 86
         wrap(phantom);
81 87
         phanta.push(phantom);
  88
+        phantom.__binaryPath = binaryPath;
82 89
         return typeof cb === "function" ? cb(phantom) : void 0;
83 90
       });
84 91
     }

No commit comments for this range

Something went wrong with that request. Please try again.