poltergeist 1.7.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/README.md +1 -1
 - data/lib/capybara/poltergeist/browser.rb +19 -8
 - data/lib/capybara/poltergeist/client/agent.coffee +37 -12
 - data/lib/capybara/poltergeist/client/browser.coffee +107 -90
 - data/lib/capybara/poltergeist/client/cmd.coffee +17 -0
 - data/lib/capybara/poltergeist/client/compiled/agent.js +97 -71
 - data/lib/capybara/poltergeist/client/compiled/browser.js +204 -173
 - data/lib/capybara/poltergeist/client/compiled/cmd.js +31 -0
 - data/lib/capybara/poltergeist/client/compiled/connection.js +2 -2
 - data/lib/capybara/poltergeist/client/compiled/main.js +45 -43
 - data/lib/capybara/poltergeist/client/compiled/node.js +10 -11
 - data/lib/capybara/poltergeist/client/compiled/web_page.js +89 -60
 - data/lib/capybara/poltergeist/client/main.coffee +12 -9
 - data/lib/capybara/poltergeist/client/node.coffee +6 -3
 - data/lib/capybara/poltergeist/client/web_page.coffee +22 -8
 - data/lib/capybara/poltergeist/command.rb +17 -0
 - data/lib/capybara/poltergeist/driver.rb +40 -4
 - data/lib/capybara/poltergeist/errors.rb +5 -1
 - data/lib/capybara/poltergeist/inspector.rb +5 -5
 - data/lib/capybara/poltergeist/node.rb +16 -1
 - data/lib/capybara/poltergeist/server.rb +2 -2
 - data/lib/capybara/poltergeist/version.rb +1 -1
 - data/lib/capybara/poltergeist/web_socket_server.rb +23 -12
 - metadata +11 -8
 
| 
         @@ -0,0 +1,17 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            class Poltergeist.Cmd
         
     | 
| 
      
 2 
     | 
    
         
            +
              constructor: (@owner, @id, @name, @args)->
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
              sendResponse: (response) ->
         
     | 
| 
      
 5 
     | 
    
         
            +
                errors = @browser.currentPage.errors
         
     | 
| 
      
 6 
     | 
    
         
            +
                @browser.currentPage.clearErrors()
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
                if errors.length > 0 && @browser.js_errors
         
     | 
| 
      
 9 
     | 
    
         
            +
                  @sendError(new Poltergeist.JavascriptError(errors))
         
     | 
| 
      
 10 
     | 
    
         
            +
                else
         
     | 
| 
      
 11 
     | 
    
         
            +
                  @owner.sendResponse(@id, response)
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
              sendError: (errors) ->
         
     | 
| 
      
 14 
     | 
    
         
            +
                @owner.sendError(@id, errors)
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
              run: (@browser) ->
         
     | 
| 
      
 17 
     | 
    
         
            +
                @browser.runCommand(this)
         
     | 
| 
         @@ -1,19 +1,24 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            var PoltergeistAgent;
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            PoltergeistAgent = (function() {
         
     | 
| 
      
 4 
     | 
    
         
            +
              PoltergeistAgent.JSON || (PoltergeistAgent.JSON = {
         
     | 
| 
      
 5 
     | 
    
         
            +
                parse: JSON.parse,
         
     | 
| 
      
 6 
     | 
    
         
            +
                stringify: JSON.stringify
         
     | 
| 
      
 7 
     | 
    
         
            +
              });
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
       4 
9 
     | 
    
         
             
              function PoltergeistAgent() {
         
     | 
| 
       5 
10 
     | 
    
         
             
                this.elements = [];
         
     | 
| 
       6 
11 
     | 
    
         
             
                this.nodes = {};
         
     | 
| 
       7 
12 
     | 
    
         
             
              }
         
     | 
| 
       8 
13 
     | 
    
         | 
| 
       9 
14 
     | 
    
         
             
              PoltergeistAgent.prototype.externalCall = function(name, args) {
         
     | 
| 
       10 
     | 
    
         
            -
                var error;
         
     | 
| 
      
 15 
     | 
    
         
            +
                var error, error1;
         
     | 
| 
       11 
16 
     | 
    
         
             
                try {
         
     | 
| 
       12 
17 
     | 
    
         
             
                  return {
         
     | 
| 
       13 
18 
     | 
    
         
             
                    value: this[name].apply(this, args)
         
     | 
| 
       14 
19 
     | 
    
         
             
                  };
         
     | 
| 
       15 
     | 
    
         
            -
                } catch ( 
     | 
| 
       16 
     | 
    
         
            -
                  error =  
     | 
| 
      
 20 
     | 
    
         
            +
                } catch (error1) {
         
     | 
| 
      
 21 
     | 
    
         
            +
                  error = error1;
         
     | 
| 
       17 
22 
     | 
    
         
             
                  return {
         
     | 
| 
       18 
23 
     | 
    
         
             
                    error: {
         
     | 
| 
       19 
24 
     | 
    
         
             
                      message: error.toString(),
         
     | 
| 
         @@ -24,17 +29,17 @@ PoltergeistAgent = (function() { 
     | 
|
| 
       24 
29 
     | 
    
         
             
              };
         
     | 
| 
       25 
30 
     | 
    
         | 
| 
       26 
31 
     | 
    
         
             
              PoltergeistAgent.stringify = function(object) {
         
     | 
| 
       27 
     | 
    
         
            -
                var error;
         
     | 
| 
      
 32 
     | 
    
         
            +
                var error, error1;
         
     | 
| 
       28 
33 
     | 
    
         
             
                try {
         
     | 
| 
       29 
     | 
    
         
            -
                  return JSON.stringify(object, function(key, value) {
         
     | 
| 
      
 34 
     | 
    
         
            +
                  return PoltergeistAgent.JSON.stringify(object, function(key, value) {
         
     | 
| 
       30 
35 
     | 
    
         
             
                    if (Array.isArray(this[key])) {
         
     | 
| 
       31 
36 
     | 
    
         
             
                      return this[key];
         
     | 
| 
       32 
37 
     | 
    
         
             
                    } else {
         
     | 
| 
       33 
38 
     | 
    
         
             
                      return value;
         
     | 
| 
       34 
39 
     | 
    
         
             
                    }
         
     | 
| 
       35 
40 
     | 
    
         
             
                  });
         
     | 
| 
       36 
     | 
    
         
            -
                } catch ( 
     | 
| 
       37 
     | 
    
         
            -
                  error =  
     | 
| 
      
 41 
     | 
    
         
            +
                } catch (error1) {
         
     | 
| 
      
 42 
     | 
    
         
            +
                  error = error1;
         
     | 
| 
       38 
43 
     | 
    
         
             
                  if (error instanceof TypeError) {
         
     | 
| 
       39 
44 
     | 
    
         
             
                    return '"(cyclic structure)"';
         
     | 
| 
       40 
45 
     | 
    
         
             
                  } else {
         
     | 
| 
         @@ -48,7 +53,7 @@ PoltergeistAgent = (function() { 
     | 
|
| 
       48 
53 
     | 
    
         
             
              };
         
     | 
| 
       49 
54 
     | 
    
         | 
| 
       50 
55 
     | 
    
         
             
              PoltergeistAgent.prototype.find = function(method, selector, within) {
         
     | 
| 
       51 
     | 
    
         
            -
                var el, error, i,  
     | 
| 
      
 56 
     | 
    
         
            +
                var el, error, error1, i, j, len, results, results1, xpath;
         
     | 
| 
       52 
57 
     | 
    
         
             
                if (within == null) {
         
     | 
| 
       53 
58 
     | 
    
         
             
                  within = document;
         
     | 
| 
       54 
59 
     | 
    
         
             
                }
         
     | 
| 
         @@ -56,24 +61,24 @@ PoltergeistAgent = (function() { 
     | 
|
| 
       56 
61 
     | 
    
         
             
                  if (method === "xpath") {
         
     | 
| 
       57 
62 
     | 
    
         
             
                    xpath = document.evaluate(selector, within, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
         
     | 
| 
       58 
63 
     | 
    
         
             
                    results = (function() {
         
     | 
| 
       59 
     | 
    
         
            -
                      var  
     | 
| 
       60 
     | 
    
         
            -
                       
     | 
| 
       61 
     | 
    
         
            -
                      for (i =  
     | 
| 
       62 
     | 
    
         
            -
                         
     | 
| 
      
 64 
     | 
    
         
            +
                      var j, ref, results1;
         
     | 
| 
      
 65 
     | 
    
         
            +
                      results1 = [];
         
     | 
| 
      
 66 
     | 
    
         
            +
                      for (i = j = 0, ref = xpath.snapshotLength; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) {
         
     | 
| 
      
 67 
     | 
    
         
            +
                        results1.push(xpath.snapshotItem(i));
         
     | 
| 
       63 
68 
     | 
    
         
             
                      }
         
     | 
| 
       64 
     | 
    
         
            -
                      return  
     | 
| 
      
 69 
     | 
    
         
            +
                      return results1;
         
     | 
| 
       65 
70 
     | 
    
         
             
                    })();
         
     | 
| 
       66 
71 
     | 
    
         
             
                  } else {
         
     | 
| 
       67 
72 
     | 
    
         
             
                    results = within.querySelectorAll(selector);
         
     | 
| 
       68 
73 
     | 
    
         
             
                  }
         
     | 
| 
       69 
     | 
    
         
            -
                   
     | 
| 
       70 
     | 
    
         
            -
                  for ( 
     | 
| 
       71 
     | 
    
         
            -
                    el = results[ 
     | 
| 
       72 
     | 
    
         
            -
                     
     | 
| 
      
 74 
     | 
    
         
            +
                  results1 = [];
         
     | 
| 
      
 75 
     | 
    
         
            +
                  for (j = 0, len = results.length; j < len; j++) {
         
     | 
| 
      
 76 
     | 
    
         
            +
                    el = results[j];
         
     | 
| 
      
 77 
     | 
    
         
            +
                    results1.push(this.register(el));
         
     | 
| 
       73 
78 
     | 
    
         
             
                  }
         
     | 
| 
       74 
     | 
    
         
            -
                  return  
     | 
| 
       75 
     | 
    
         
            -
                } catch ( 
     | 
| 
       76 
     | 
    
         
            -
                  error =  
     | 
| 
      
 79 
     | 
    
         
            +
                  return results1;
         
     | 
| 
      
 80 
     | 
    
         
            +
                } catch (error1) {
         
     | 
| 
      
 81 
     | 
    
         
            +
                  error = error1;
         
     | 
| 
       77 
82 
     | 
    
         
             
                  if (error.code === DOMException.SYNTAX_ERR || error.code === 51) {
         
     | 
| 
       78 
83 
     | 
    
         
             
                    throw new PoltergeistAgent.InvalidSelector;
         
     | 
| 
       79 
84 
     | 
    
         
             
                  } else {
         
     | 
| 
         @@ -95,8 +100,8 @@ PoltergeistAgent = (function() { 
     | 
|
| 
       95 
100 
     | 
    
         
             
              };
         
     | 
| 
       96 
101 
     | 
    
         | 
| 
       97 
102 
     | 
    
         
             
              PoltergeistAgent.prototype.get = function(id) {
         
     | 
| 
       98 
     | 
    
         
            -
                var  
     | 
| 
       99 
     | 
    
         
            -
                return ( 
     | 
| 
      
 103 
     | 
    
         
            +
                var base;
         
     | 
| 
      
 104 
     | 
    
         
            +
                return (base = this.nodes)[id] || (base[id] = new PoltergeistAgent.Node(this, this.elements[id]));
         
     | 
| 
       100 
105 
     | 
    
         
             
              };
         
     | 
| 
       101 
106 
     | 
    
         | 
| 
       102 
107 
     | 
    
         
             
              PoltergeistAgent.prototype.nodeCall = function(id, name, args) {
         
     | 
| 
         @@ -153,9 +158,9 @@ PoltergeistAgent.Node = (function() { 
     | 
|
| 
       153 
158 
     | 
    
         
             
                FORM: ['submit']
         
     | 
| 
       154 
159 
     | 
    
         
             
              };
         
     | 
| 
       155 
160 
     | 
    
         | 
| 
       156 
     | 
    
         
            -
              function Node(agent,  
     | 
| 
      
 161 
     | 
    
         
            +
              function Node(agent, element1) {
         
     | 
| 
       157 
162 
     | 
    
         
             
                this.agent = agent;
         
     | 
| 
       158 
     | 
    
         
            -
                this.element =  
     | 
| 
      
 163 
     | 
    
         
            +
                this.element = element1;
         
     | 
| 
       159 
164 
     | 
    
         
             
              }
         
     | 
| 
       160 
165 
     | 
    
         | 
| 
       161 
166 
     | 
    
         
             
              Node.prototype.parentId = function() {
         
     | 
| 
         @@ -178,19 +183,20 @@ PoltergeistAgent.Node = (function() { 
     | 
|
| 
       178 
183 
     | 
    
         
             
              };
         
     | 
| 
       179 
184 
     | 
    
         | 
| 
       180 
185 
     | 
    
         
             
              Node.prototype.isObsolete = function() {
         
     | 
| 
       181 
     | 
    
         
            -
                var obsolete 
     | 
| 
       182 
     | 
    
         
            -
             
     | 
| 
       183 
     | 
    
         
            -
             
     | 
| 
       184 
     | 
    
         
            -
             
     | 
| 
       185 
     | 
    
         
            -
             
     | 
| 
       186 
     | 
    
         
            -
             
     | 
| 
      
 186 
     | 
    
         
            +
                var obsolete;
         
     | 
| 
      
 187 
     | 
    
         
            +
                obsolete = (function(_this) {
         
     | 
| 
      
 188 
     | 
    
         
            +
                  return function(element) {
         
     | 
| 
      
 189 
     | 
    
         
            +
                    if (element.parentNode != null) {
         
     | 
| 
      
 190 
     | 
    
         
            +
                      if (element.parentNode === document) {
         
     | 
| 
      
 191 
     | 
    
         
            +
                        return false;
         
     | 
| 
      
 192 
     | 
    
         
            +
                      } else {
         
     | 
| 
      
 193 
     | 
    
         
            +
                        return obsolete(element.parentNode);
         
     | 
| 
      
 194 
     | 
    
         
            +
                      }
         
     | 
| 
       187 
195 
     | 
    
         
             
                    } else {
         
     | 
| 
       188 
     | 
    
         
            -
                      return  
     | 
| 
      
 196 
     | 
    
         
            +
                      return true;
         
     | 
| 
       189 
197 
     | 
    
         
             
                    }
         
     | 
| 
       190 
     | 
    
         
            -
                  } 
     | 
| 
       191 
     | 
    
         
            -
             
     | 
| 
       192 
     | 
    
         
            -
                  }
         
     | 
| 
       193 
     | 
    
         
            -
                };
         
     | 
| 
      
 198 
     | 
    
         
            +
                  };
         
     | 
| 
      
 199 
     | 
    
         
            +
                })(this);
         
     | 
| 
       194 
200 
     | 
    
         
             
                return obsolete(this.element);
         
     | 
| 
       195 
201 
     | 
    
         
             
              };
         
     | 
| 
       196 
202 
     | 
    
         | 
| 
         @@ -200,6 +206,10 @@ PoltergeistAgent.Node = (function() { 
     | 
|
| 
       200 
206 
     | 
    
         
             
                event.initEvent('change', true, false);
         
     | 
| 
       201 
207 
     | 
    
         
             
                if (this.element.nodeName === 'OPTION') {
         
     | 
| 
       202 
208 
     | 
    
         
             
                  element = this.element.parentNode;
         
     | 
| 
      
 209 
     | 
    
         
            +
                  if (element.nodeName === 'OPTGROUP') {
         
     | 
| 
      
 210 
     | 
    
         
            +
                    element = element.parentNode;
         
     | 
| 
      
 211 
     | 
    
         
            +
                  }
         
     | 
| 
      
 212 
     | 
    
         
            +
                  element;
         
     | 
| 
       203 
213 
     | 
    
         
             
                } else {
         
     | 
| 
       204 
214 
     | 
    
         
             
                  element = this.element;
         
     | 
| 
       205 
215 
     | 
    
         
             
                }
         
     | 
| 
         @@ -265,12 +275,16 @@ PoltergeistAgent.Node = (function() { 
     | 
|
| 
       265 
275 
     | 
    
         
             
                return window.getSelection().deleteFromDocument();
         
     | 
| 
       266 
276 
     | 
    
         
             
              };
         
     | 
| 
       267 
277 
     | 
    
         | 
| 
      
 278 
     | 
    
         
            +
              Node.prototype.getProperty = function(name) {
         
     | 
| 
      
 279 
     | 
    
         
            +
                return this.element[name];
         
     | 
| 
      
 280 
     | 
    
         
            +
              };
         
     | 
| 
      
 281 
     | 
    
         
            +
             
     | 
| 
       268 
282 
     | 
    
         
             
              Node.prototype.getAttributes = function() {
         
     | 
| 
       269 
     | 
    
         
            -
                var attr, attrs,  
     | 
| 
      
 283 
     | 
    
         
            +
                var attr, attrs, j, len, ref;
         
     | 
| 
       270 
284 
     | 
    
         
             
                attrs = {};
         
     | 
| 
       271 
     | 
    
         
            -
                 
     | 
| 
       272 
     | 
    
         
            -
                for ( 
     | 
| 
       273 
     | 
    
         
            -
                  attr =  
     | 
| 
      
 285 
     | 
    
         
            +
                ref = this.element.attributes;
         
     | 
| 
      
 286 
     | 
    
         
            +
                for (j = 0, len = ref.length; j < len; j++) {
         
     | 
| 
      
 287 
     | 
    
         
            +
                  attr = ref[j];
         
     | 
| 
       274 
288 
     | 
    
         
             
                  attrs[attr.name] = attr.value.replace("\n", "\\n");
         
     | 
| 
       275 
289 
     | 
    
         
             
                }
         
     | 
| 
       276 
290 
     | 
    
         
             
                return attrs;
         
     | 
| 
         @@ -285,41 +299,44 @@ PoltergeistAgent.Node = (function() { 
     | 
|
| 
       285 
299 
     | 
    
         
             
              };
         
     | 
| 
       286 
300 
     | 
    
         | 
| 
       287 
301 
     | 
    
         
             
              Node.prototype.scrollIntoView = function() {
         
     | 
| 
       288 
     | 
    
         
            -
                 
     | 
| 
      
 302 
     | 
    
         
            +
                this.element.scrollIntoViewIfNeeded();
         
     | 
| 
      
 303 
     | 
    
         
            +
                if (!this.isInViewport()) {
         
     | 
| 
      
 304 
     | 
    
         
            +
                  return this.element.scrollIntoView();
         
     | 
| 
      
 305 
     | 
    
         
            +
                }
         
     | 
| 
       289 
306 
     | 
    
         
             
              };
         
     | 
| 
       290 
307 
     | 
    
         | 
| 
       291 
308 
     | 
    
         
             
              Node.prototype.value = function() {
         
     | 
| 
       292 
     | 
    
         
            -
                var  
     | 
| 
      
 309 
     | 
    
         
            +
                var j, len, option, ref, results1;
         
     | 
| 
       293 
310 
     | 
    
         
             
                if (this.element.tagName === 'SELECT' && this.element.multiple) {
         
     | 
| 
       294 
     | 
    
         
            -
                   
     | 
| 
       295 
     | 
    
         
            -
                   
     | 
| 
       296 
     | 
    
         
            -
                  for ( 
     | 
| 
       297 
     | 
    
         
            -
                    option =  
     | 
| 
      
 311 
     | 
    
         
            +
                  ref = this.element.children;
         
     | 
| 
      
 312 
     | 
    
         
            +
                  results1 = [];
         
     | 
| 
      
 313 
     | 
    
         
            +
                  for (j = 0, len = ref.length; j < len; j++) {
         
     | 
| 
      
 314 
     | 
    
         
            +
                    option = ref[j];
         
     | 
| 
       298 
315 
     | 
    
         
             
                    if (option.selected) {
         
     | 
| 
       299 
     | 
    
         
            -
                       
     | 
| 
      
 316 
     | 
    
         
            +
                      results1.push(option.value);
         
     | 
| 
       300 
317 
     | 
    
         
             
                    }
         
     | 
| 
       301 
318 
     | 
    
         
             
                  }
         
     | 
| 
       302 
     | 
    
         
            -
                  return  
     | 
| 
      
 319 
     | 
    
         
            +
                  return results1;
         
     | 
| 
       303 
320 
     | 
    
         
             
                } else {
         
     | 
| 
       304 
321 
     | 
    
         
             
                  return this.element.value;
         
     | 
| 
       305 
322 
     | 
    
         
             
                }
         
     | 
| 
       306 
323 
     | 
    
         
             
              };
         
     | 
| 
       307 
324 
     | 
    
         | 
| 
       308 
325 
     | 
    
         
             
              Node.prototype.set = function(value) {
         
     | 
| 
       309 
     | 
    
         
            -
                var char,  
     | 
| 
      
 326 
     | 
    
         
            +
                var char, j, keyCode, len;
         
     | 
| 
       310 
327 
     | 
    
         
             
                if (this.element.readOnly) {
         
     | 
| 
       311 
328 
     | 
    
         
             
                  return;
         
     | 
| 
       312 
329 
     | 
    
         
             
                }
         
     | 
| 
       313 
330 
     | 
    
         
             
                if (this.element.maxLength >= 0) {
         
     | 
| 
       314 
331 
     | 
    
         
             
                  value = value.substr(0, this.element.maxLength);
         
     | 
| 
       315 
332 
     | 
    
         
             
                }
         
     | 
| 
       316 
     | 
    
         
            -
                this.element.value = '';
         
     | 
| 
       317 
333 
     | 
    
         
             
                this.trigger('focus');
         
     | 
| 
      
 334 
     | 
    
         
            +
                this.element.value = '';
         
     | 
| 
       318 
335 
     | 
    
         
             
                if (this.element.type === 'number') {
         
     | 
| 
       319 
336 
     | 
    
         
             
                  this.element.value = value;
         
     | 
| 
       320 
337 
     | 
    
         
             
                } else {
         
     | 
| 
       321 
     | 
    
         
            -
                  for ( 
     | 
| 
       322 
     | 
    
         
            -
                    char = value[ 
     | 
| 
      
 338 
     | 
    
         
            +
                  for (j = 0, len = value.length; j < len; j++) {
         
     | 
| 
      
 339 
     | 
    
         
            +
                    char = value[j];
         
     | 
| 
       323 
340 
     | 
    
         
             
                    keyCode = this.characterToKeyCode(char);
         
     | 
| 
       324 
341 
     | 
    
         
             
                    this.keyupdowned('keydown', keyCode);
         
     | 
| 
       325 
342 
     | 
    
         
             
                    this.element.value += char;
         
     | 
| 
         @@ -363,16 +380,22 @@ PoltergeistAgent.Node = (function() { 
     | 
|
| 
       363 
380 
     | 
    
         
             
              };
         
     | 
| 
       364 
381 
     | 
    
         | 
| 
       365 
382 
     | 
    
         
             
              Node.prototype.isVisible = function(element) {
         
     | 
| 
       366 
     | 
    
         
            -
                 
     | 
| 
       367 
     | 
    
         
            -
             
     | 
| 
       368 
     | 
    
         
            -
                 
     | 
| 
       369 
     | 
    
         
            -
             
     | 
| 
       370 
     | 
    
         
            -
                   
     | 
| 
       371 
     | 
    
         
            -
             
     | 
| 
       372 
     | 
    
         
            -
                   
     | 
| 
       373 
     | 
    
         
            -
             
     | 
| 
       374 
     | 
    
         
            -
                  return true;
         
     | 
| 
      
 383 
     | 
    
         
            +
                var style;
         
     | 
| 
      
 384 
     | 
    
         
            +
                element || (element = this.element);
         
     | 
| 
      
 385 
     | 
    
         
            +
                while (element) {
         
     | 
| 
      
 386 
     | 
    
         
            +
                  style = window.getComputedStyle(element);
         
     | 
| 
      
 387 
     | 
    
         
            +
                  if (style.display === 'none' || style.visibility === 'hidden' || parseFloat(style.opacity) === 0) {
         
     | 
| 
      
 388 
     | 
    
         
            +
                    return false;
         
     | 
| 
      
 389 
     | 
    
         
            +
                  }
         
     | 
| 
      
 390 
     | 
    
         
            +
                  element = element.parentElement;
         
     | 
| 
       375 
391 
     | 
    
         
             
                }
         
     | 
| 
      
 392 
     | 
    
         
            +
                return true;
         
     | 
| 
      
 393 
     | 
    
         
            +
              };
         
     | 
| 
      
 394 
     | 
    
         
            +
             
     | 
| 
      
 395 
     | 
    
         
            +
              Node.prototype.isInViewport = function() {
         
     | 
| 
      
 396 
     | 
    
         
            +
                var rect;
         
     | 
| 
      
 397 
     | 
    
         
            +
                rect = this.element.getBoundingClientRect();
         
     | 
| 
      
 398 
     | 
    
         
            +
                return rect.top >= 0 && rect.left >= 0 && rect.bottom <= window.innerHeight && rect.right <= window.innerWidth;
         
     | 
| 
       376 
399 
     | 
    
         
             
              };
         
     | 
| 
       377 
400 
     | 
    
         | 
| 
       378 
401 
     | 
    
         
             
              Node.prototype.isDisabled = function() {
         
     | 
| 
         @@ -380,16 +403,17 @@ PoltergeistAgent.Node = (function() { 
     | 
|
| 
       380 
403 
     | 
    
         
             
              };
         
     | 
| 
       381 
404 
     | 
    
         | 
| 
       382 
405 
     | 
    
         
             
              Node.prototype.path = function() {
         
     | 
| 
       383 
     | 
    
         
            -
                var elements, selectors 
     | 
| 
       384 
     | 
    
         
            -
             
     | 
| 
       385 
     | 
    
         
            -
             
     | 
| 
       386 
     | 
    
         
            -
             
     | 
| 
       387 
     | 
    
         
            -
             
     | 
| 
      
 406 
     | 
    
         
            +
                var elements, selectors;
         
     | 
| 
      
 407 
     | 
    
         
            +
                elements = this.parentIds().reverse().map((function(_this) {
         
     | 
| 
      
 408 
     | 
    
         
            +
                  return function(id) {
         
     | 
| 
      
 409 
     | 
    
         
            +
                    return _this.agent.get(id);
         
     | 
| 
      
 410 
     | 
    
         
            +
                  };
         
     | 
| 
      
 411 
     | 
    
         
            +
                })(this));
         
     | 
| 
       388 
412 
     | 
    
         
             
                elements.push(this);
         
     | 
| 
       389 
413 
     | 
    
         
             
                selectors = elements.map(function(el) {
         
     | 
| 
       390 
414 
     | 
    
         
             
                  var prev_siblings;
         
     | 
| 
       391 
415 
     | 
    
         
             
                  prev_siblings = el.find('xpath', "./preceding-sibling::" + (el.tagName()));
         
     | 
| 
       392 
     | 
    
         
            -
                  return  
     | 
| 
      
 416 
     | 
    
         
            +
                  return (el.tagName()) + "[" + (prev_siblings.length + 1) + "]";
         
     | 
| 
       393 
417 
     | 
    
         
             
                });
         
     | 
| 
       394 
418 
     | 
    
         
             
                return "//" + selectors.join('/');
         
     | 
| 
       395 
419 
     | 
    
         
             
              };
         
     | 
| 
         @@ -488,16 +512,18 @@ PoltergeistAgent.Node = (function() { 
     | 
|
| 
       488 
512 
     | 
    
         
             
              };
         
     | 
| 
       489 
513 
     | 
    
         | 
| 
       490 
514 
     | 
    
         
             
              Node.prototype.getSelector = function(el) {
         
     | 
| 
       491 
     | 
    
         
            -
                var className,  
     | 
| 
      
 515 
     | 
    
         
            +
                var className, classes, j, len, ref, ref1, selector;
         
     | 
| 
       492 
516 
     | 
    
         
             
                selector = el.tagName !== 'HTML' ? this.getSelector(el.parentNode) + ' ' : '';
         
     | 
| 
       493 
517 
     | 
    
         
             
                selector += el.tagName.toLowerCase();
         
     | 
| 
       494 
518 
     | 
    
         
             
                if (el.id) {
         
     | 
| 
       495 
519 
     | 
    
         
             
                  selector += "#" + el.id;
         
     | 
| 
       496 
520 
     | 
    
         
             
                }
         
     | 
| 
       497 
     | 
    
         
            -
                 
     | 
| 
       498 
     | 
    
         
            -
                for ( 
     | 
| 
       499 
     | 
    
         
            -
                  className =  
     | 
| 
       500 
     | 
    
         
            -
                   
     | 
| 
      
 521 
     | 
    
         
            +
                classes = el.classList || ((ref = el.getAttribute('class')) != null ? (ref1 = ref.trim()) != null ? ref1.split(/\s+/) : void 0 : void 0) || [];
         
     | 
| 
      
 522 
     | 
    
         
            +
                for (j = 0, len = classes.length; j < len; j++) {
         
     | 
| 
      
 523 
     | 
    
         
            +
                  className = classes[j];
         
     | 
| 
      
 524 
     | 
    
         
            +
                  if (className !== '') {
         
     | 
| 
      
 525 
     | 
    
         
            +
                    selector += "." + className;
         
     | 
| 
      
 526 
     | 
    
         
            +
                  }
         
     | 
| 
       501 
527 
     | 
    
         
             
                }
         
     | 
| 
       502 
528 
     | 
    
         
             
                return selector;
         
     | 
| 
       503 
529 
     | 
    
         
             
              };
         
     | 
| 
         @@ -1,8 +1,7 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            var  
     | 
| 
      
 1 
     | 
    
         
            +
            var indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            Poltergeist.Browser = (function() {
         
     | 
| 
       4 
     | 
    
         
            -
              function Browser( 
     | 
| 
       5 
     | 
    
         
            -
                this.owner = owner;
         
     | 
| 
      
 4 
     | 
    
         
            +
              function Browser(width, height) {
         
     | 
| 
       6 
5 
     | 
    
         
             
                this.width = width || 1024;
         
     | 
| 
       7 
6 
     | 
    
         
             
                this.height = height || 768;
         
     | 
| 
       8 
7 
     | 
    
         
             
                this.pages = [];
         
     | 
| 
         @@ -16,9 +15,8 @@ Poltergeist.Browser = (function() { 
     | 
|
| 
       16 
15 
     | 
    
         
             
              }
         
     | 
| 
       17 
16 
     | 
    
         | 
| 
       18 
17 
     | 
    
         
             
              Browser.prototype.resetPage = function() {
         
     | 
| 
       19 
     | 
    
         
            -
                var  
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
                _ref = [0, []], this._counter = _ref[0], this.pages = _ref[1];
         
     | 
| 
      
 18 
     | 
    
         
            +
                var ref;
         
     | 
| 
      
 19 
     | 
    
         
            +
                ref = [0, []], this._counter = ref[0], this.pages = ref[1];
         
     | 
| 
       22 
20 
     | 
    
         
             
                if (this.page != null) {
         
     | 
| 
       23 
21 
     | 
    
         
             
                  if (!this.page.closed) {
         
     | 
| 
       24 
22 
     | 
    
         
             
                    if (this.page.currentUrl() !== 'about:blank') {
         
     | 
| 
         @@ -38,33 +36,41 @@ Poltergeist.Browser = (function() { 
     | 
|
| 
       38 
36 
     | 
    
         
             
                this.processed_modal_messages = [];
         
     | 
| 
       39 
37 
     | 
    
         
             
                this.confirm_processes = [];
         
     | 
| 
       40 
38 
     | 
    
         
             
                this.prompt_responses = [];
         
     | 
| 
       41 
     | 
    
         
            -
                this.page["native"]().onAlert = function( 
     | 
| 
       42 
     | 
    
         
            -
                   
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
                   
     | 
| 
       48 
     | 
    
         
            -
                    process 
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
                   
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
                   
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
                   
     | 
| 
       67 
     | 
    
         
            -
                };
         
     | 
| 
      
 39 
     | 
    
         
            +
                this.page["native"]().onAlert = (function(_this) {
         
     | 
| 
      
 40 
     | 
    
         
            +
                  return function(msg) {
         
     | 
| 
      
 41 
     | 
    
         
            +
                    _this.setModalMessage(msg);
         
     | 
| 
      
 42 
     | 
    
         
            +
                  };
         
     | 
| 
      
 43 
     | 
    
         
            +
                })(this);
         
     | 
| 
      
 44 
     | 
    
         
            +
                this.page["native"]().onConfirm = (function(_this) {
         
     | 
| 
      
 45 
     | 
    
         
            +
                  return function(msg) {
         
     | 
| 
      
 46 
     | 
    
         
            +
                    var process;
         
     | 
| 
      
 47 
     | 
    
         
            +
                    process = _this.confirm_processes.pop();
         
     | 
| 
      
 48 
     | 
    
         
            +
                    if (process === void 0) {
         
     | 
| 
      
 49 
     | 
    
         
            +
                      process = true;
         
     | 
| 
      
 50 
     | 
    
         
            +
                    }
         
     | 
| 
      
 51 
     | 
    
         
            +
                    _this.setModalMessage(msg);
         
     | 
| 
      
 52 
     | 
    
         
            +
                    return process;
         
     | 
| 
      
 53 
     | 
    
         
            +
                  };
         
     | 
| 
      
 54 
     | 
    
         
            +
                })(this);
         
     | 
| 
      
 55 
     | 
    
         
            +
                this.page["native"]().onPrompt = (function(_this) {
         
     | 
| 
      
 56 
     | 
    
         
            +
                  return function(msg, defaultVal) {
         
     | 
| 
      
 57 
     | 
    
         
            +
                    var response;
         
     | 
| 
      
 58 
     | 
    
         
            +
                    response = _this.prompt_responses.pop();
         
     | 
| 
      
 59 
     | 
    
         
            +
                    if (response === void 0 || response === false) {
         
     | 
| 
      
 60 
     | 
    
         
            +
                      response = defaultVal;
         
     | 
| 
      
 61 
     | 
    
         
            +
                    }
         
     | 
| 
      
 62 
     | 
    
         
            +
                    _this.setModalMessage(msg);
         
     | 
| 
      
 63 
     | 
    
         
            +
                    return response;
         
     | 
| 
      
 64 
     | 
    
         
            +
                  };
         
     | 
| 
      
 65 
     | 
    
         
            +
                })(this);
         
     | 
| 
      
 66 
     | 
    
         
            +
                return this.page.onPageCreated = (function(_this) {
         
     | 
| 
      
 67 
     | 
    
         
            +
                  return function(newPage) {
         
     | 
| 
      
 68 
     | 
    
         
            +
                    var page;
         
     | 
| 
      
 69 
     | 
    
         
            +
                    page = new Poltergeist.WebPage(newPage);
         
     | 
| 
      
 70 
     | 
    
         
            +
                    page.handle = "" + (_this._counter++);
         
     | 
| 
      
 71 
     | 
    
         
            +
                    return _this.pages.push(page);
         
     | 
| 
      
 72 
     | 
    
         
            +
                  };
         
     | 
| 
      
 73 
     | 
    
         
            +
                })(this);
         
     | 
| 
       68 
74 
     | 
    
         
             
              };
         
     | 
| 
       69 
75 
     | 
    
         | 
| 
       70 
76 
     | 
    
         
             
              Browser.prototype.getPageByHandle = function(handle) {
         
     | 
| 
         @@ -73,9 +79,10 @@ Poltergeist.Browser = (function() { 
     | 
|
| 
       73 
79 
     | 
    
         
             
                })[0];
         
     | 
| 
       74 
80 
     | 
    
         
             
              };
         
     | 
| 
       75 
81 
     | 
    
         | 
| 
       76 
     | 
    
         
            -
              Browser.prototype.runCommand = function( 
     | 
| 
      
 82 
     | 
    
         
            +
              Browser.prototype.runCommand = function(command) {
         
     | 
| 
      
 83 
     | 
    
         
            +
                this.current_command = command;
         
     | 
| 
       77 
84 
     | 
    
         
             
                this.currentPage.state = 'default';
         
     | 
| 
       78 
     | 
    
         
            -
                return this[name].apply(this, args);
         
     | 
| 
      
 85 
     | 
    
         
            +
                return this[command.name].apply(this, command.args);
         
     | 
| 
       79 
86 
     | 
    
         
             
              };
         
     | 
| 
       80 
87 
     | 
    
         | 
| 
       81 
88 
     | 
    
         
             
              Browser.prototype.debug = function(message) {
         
     | 
| 
         @@ -88,20 +95,9 @@ Poltergeist.Browser = (function() { 
     | 
|
| 
       88 
95 
     | 
    
         
             
                return this.processed_modal_messages.push(msg);
         
     | 
| 
       89 
96 
     | 
    
         
             
              };
         
     | 
| 
       90 
97 
     | 
    
         | 
| 
       91 
     | 
    
         
            -
              Browser.prototype.sendResponse = function(response) {
         
     | 
| 
       92 
     | 
    
         
            -
                var errors;
         
     | 
| 
       93 
     | 
    
         
            -
                errors = this.currentPage.errors;
         
     | 
| 
       94 
     | 
    
         
            -
                this.currentPage.clearErrors();
         
     | 
| 
       95 
     | 
    
         
            -
                if (errors.length > 0 && this.js_errors) {
         
     | 
| 
       96 
     | 
    
         
            -
                  return this.owner.sendError(new Poltergeist.JavascriptError(errors));
         
     | 
| 
       97 
     | 
    
         
            -
                } else {
         
     | 
| 
       98 
     | 
    
         
            -
                  return this.owner.sendResponse(response);
         
     | 
| 
       99 
     | 
    
         
            -
                }
         
     | 
| 
       100 
     | 
    
         
            -
              };
         
     | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
       102 
98 
     | 
    
         
             
              Browser.prototype.add_extension = function(extension) {
         
     | 
| 
       103 
99 
     | 
    
         
             
                this.currentPage.injectExtension(extension);
         
     | 
| 
       104 
     | 
    
         
            -
                return this.sendResponse('success');
         
     | 
| 
      
 100 
     | 
    
         
            +
                return this.current_command.sendResponse('success');
         
     | 
| 
       105 
101 
     | 
    
         
             
              };
         
     | 
| 
       106 
102 
     | 
    
         | 
| 
       107 
103 
     | 
    
         
             
              Browser.prototype.node = function(page_id, id) {
         
     | 
| 
         @@ -113,8 +109,7 @@ Poltergeist.Browser = (function() { 
     | 
|
| 
       113 
109 
     | 
    
         
             
              };
         
     | 
| 
       114 
110 
     | 
    
         | 
| 
       115 
111 
     | 
    
         
             
              Browser.prototype.visit = function(url) {
         
     | 
| 
       116 
     | 
    
         
            -
                var prevUrl 
     | 
| 
       117 
     | 
    
         
            -
                  _this = this;
         
     | 
| 
      
 112 
     | 
    
         
            +
                var command, prevUrl;
         
     | 
| 
       118 
113 
     | 
    
         
             
                this.currentPage.state = 'loading';
         
     | 
| 
       119 
114 
     | 
    
         
             
                this.processed_modal_messages = [];
         
     | 
| 
       120 
115 
     | 
    
         
             
                this.confirm_processes = [];
         
     | 
| 
         @@ -123,84 +118,91 @@ Poltergeist.Browser = (function() { 
     | 
|
| 
       123 
118 
     | 
    
         
             
                this.currentPage.open(url);
         
     | 
| 
       124 
119 
     | 
    
         
             
                if (/#/.test(url) && prevUrl.split('#')[0] === url.split('#')[0]) {
         
     | 
| 
       125 
120 
     | 
    
         
             
                  this.currentPage.state = 'default';
         
     | 
| 
       126 
     | 
    
         
            -
                  return this.sendResponse({
         
     | 
| 
      
 121 
     | 
    
         
            +
                  return this.current_command.sendResponse({
         
     | 
| 
       127 
122 
     | 
    
         
             
                    status: 'success'
         
     | 
| 
       128 
123 
     | 
    
         
             
                  });
         
     | 
| 
       129 
124 
     | 
    
         
             
                } else {
         
     | 
| 
       130 
     | 
    
         
            -
                   
     | 
| 
       131 
     | 
    
         
            -
             
     | 
| 
       132 
     | 
    
         
            -
             
     | 
| 
       133 
     | 
    
         
            -
             
     | 
| 
       134 
     | 
    
         
            -
             
     | 
| 
       135 
     | 
    
         
            -
             
     | 
| 
       136 
     | 
    
         
            -
             
     | 
| 
       137 
     | 
    
         
            -
             
     | 
| 
       138 
     | 
    
         
            -
             
     | 
| 
      
 125 
     | 
    
         
            +
                  command = this.current_command;
         
     | 
| 
      
 126 
     | 
    
         
            +
                  return this.currentPage.waitState('default', (function(_this) {
         
     | 
| 
      
 127 
     | 
    
         
            +
                    return function() {
         
     | 
| 
      
 128 
     | 
    
         
            +
                      if (_this.currentPage.statusCode === null && _this.currentPage.status === 'fail') {
         
     | 
| 
      
 129 
     | 
    
         
            +
                        return command.sendError(new Poltergeist.StatusFailError(url));
         
     | 
| 
      
 130 
     | 
    
         
            +
                      } else {
         
     | 
| 
      
 131 
     | 
    
         
            +
                        return command.sendResponse({
         
     | 
| 
      
 132 
     | 
    
         
            +
                          status: _this.currentPage.status
         
     | 
| 
      
 133 
     | 
    
         
            +
                        });
         
     | 
| 
      
 134 
     | 
    
         
            +
                      }
         
     | 
| 
      
 135 
     | 
    
         
            +
                    };
         
     | 
| 
      
 136 
     | 
    
         
            +
                  })(this));
         
     | 
| 
       139 
137 
     | 
    
         
             
                }
         
     | 
| 
       140 
138 
     | 
    
         
             
              };
         
     | 
| 
       141 
139 
     | 
    
         | 
| 
       142 
140 
     | 
    
         
             
              Browser.prototype.current_url = function() {
         
     | 
| 
       143 
     | 
    
         
            -
                return this.sendResponse(this.currentPage.currentUrl());
         
     | 
| 
      
 141 
     | 
    
         
            +
                return this.current_command.sendResponse(this.currentPage.currentUrl());
         
     | 
| 
       144 
142 
     | 
    
         
             
              };
         
     | 
| 
       145 
143 
     | 
    
         | 
| 
       146 
144 
     | 
    
         
             
              Browser.prototype.status_code = function() {
         
     | 
| 
       147 
     | 
    
         
            -
                return this.sendResponse(this.currentPage.statusCode);
         
     | 
| 
      
 145 
     | 
    
         
            +
                return this.current_command.sendResponse(this.currentPage.statusCode);
         
     | 
| 
       148 
146 
     | 
    
         
             
              };
         
     | 
| 
       149 
147 
     | 
    
         | 
| 
       150 
148 
     | 
    
         
             
              Browser.prototype.body = function() {
         
     | 
| 
       151 
     | 
    
         
            -
                return this.sendResponse(this.currentPage.content());
         
     | 
| 
      
 149 
     | 
    
         
            +
                return this.current_command.sendResponse(this.currentPage.content());
         
     | 
| 
       152 
150 
     | 
    
         
             
              };
         
     | 
| 
       153 
151 
     | 
    
         | 
| 
       154 
152 
     | 
    
         
             
              Browser.prototype.source = function() {
         
     | 
| 
       155 
     | 
    
         
            -
                return this.sendResponse(this.currentPage.source);
         
     | 
| 
      
 153 
     | 
    
         
            +
                return this.current_command.sendResponse(this.currentPage.source);
         
     | 
| 
       156 
154 
     | 
    
         
             
              };
         
     | 
| 
       157 
155 
     | 
    
         | 
| 
       158 
156 
     | 
    
         
             
              Browser.prototype.title = function() {
         
     | 
| 
       159 
     | 
    
         
            -
                return this.sendResponse(this.currentPage.title());
         
     | 
| 
      
 157 
     | 
    
         
            +
                return this.current_command.sendResponse(this.currentPage.title());
         
     | 
| 
       160 
158 
     | 
    
         
             
              };
         
     | 
| 
       161 
159 
     | 
    
         | 
| 
       162 
160 
     | 
    
         
             
              Browser.prototype.find = function(method, selector) {
         
     | 
| 
       163 
     | 
    
         
            -
                return this.sendResponse({
         
     | 
| 
      
 161 
     | 
    
         
            +
                return this.current_command.sendResponse({
         
     | 
| 
       164 
162 
     | 
    
         
             
                  page_id: this.currentPage.id,
         
     | 
| 
       165 
163 
     | 
    
         
             
                  ids: this.currentPage.find(method, selector)
         
     | 
| 
       166 
164 
     | 
    
         
             
                });
         
     | 
| 
       167 
165 
     | 
    
         
             
              };
         
     | 
| 
       168 
166 
     | 
    
         | 
| 
       169 
167 
     | 
    
         
             
              Browser.prototype.find_within = function(page_id, id, method, selector) {
         
     | 
| 
       170 
     | 
    
         
            -
                return this.sendResponse(this.node(page_id, id).find(method, selector));
         
     | 
| 
      
 168 
     | 
    
         
            +
                return this.current_command.sendResponse(this.node(page_id, id).find(method, selector));
         
     | 
| 
       171 
169 
     | 
    
         
             
              };
         
     | 
| 
       172 
170 
     | 
    
         | 
| 
       173 
171 
     | 
    
         
             
              Browser.prototype.all_text = function(page_id, id) {
         
     | 
| 
       174 
     | 
    
         
            -
                return this.sendResponse(this.node(page_id, id).allText());
         
     | 
| 
      
 172 
     | 
    
         
            +
                return this.current_command.sendResponse(this.node(page_id, id).allText());
         
     | 
| 
       175 
173 
     | 
    
         
             
              };
         
     | 
| 
       176 
174 
     | 
    
         | 
| 
       177 
175 
     | 
    
         
             
              Browser.prototype.visible_text = function(page_id, id) {
         
     | 
| 
       178 
     | 
    
         
            -
                return this.sendResponse(this.node(page_id, id).visibleText());
         
     | 
| 
      
 176 
     | 
    
         
            +
                return this.current_command.sendResponse(this.node(page_id, id).visibleText());
         
     | 
| 
       179 
177 
     | 
    
         
             
              };
         
     | 
| 
       180 
178 
     | 
    
         | 
| 
       181 
179 
     | 
    
         
             
              Browser.prototype.delete_text = function(page_id, id) {
         
     | 
| 
       182 
     | 
    
         
            -
                return this.sendResponse(this.node(page_id, id).deleteText());
         
     | 
| 
      
 180 
     | 
    
         
            +
                return this.current_command.sendResponse(this.node(page_id, id).deleteText());
         
     | 
| 
      
 181 
     | 
    
         
            +
              };
         
     | 
| 
      
 182 
     | 
    
         
            +
             
     | 
| 
      
 183 
     | 
    
         
            +
              Browser.prototype.property = function(page_id, id, name) {
         
     | 
| 
      
 184 
     | 
    
         
            +
                return this.current_command.sendResponse(this.node(page_id, id).getProperty(name));
         
     | 
| 
       183 
185 
     | 
    
         
             
              };
         
     | 
| 
       184 
186 
     | 
    
         | 
| 
       185 
187 
     | 
    
         
             
              Browser.prototype.attribute = function(page_id, id, name) {
         
     | 
| 
       186 
     | 
    
         
            -
                return this.sendResponse(this.node(page_id, id).getAttribute(name));
         
     | 
| 
      
 188 
     | 
    
         
            +
                return this.current_command.sendResponse(this.node(page_id, id).getAttribute(name));
         
     | 
| 
       187 
189 
     | 
    
         
             
              };
         
     | 
| 
       188 
190 
     | 
    
         | 
| 
       189 
191 
     | 
    
         
             
              Browser.prototype.attributes = function(page_id, id, name) {
         
     | 
| 
       190 
     | 
    
         
            -
                return this.sendResponse(this.node(page_id, id).getAttributes());
         
     | 
| 
      
 192 
     | 
    
         
            +
                return this.current_command.sendResponse(this.node(page_id, id).getAttributes());
         
     | 
| 
       191 
193 
     | 
    
         
             
              };
         
     | 
| 
       192 
194 
     | 
    
         | 
| 
       193 
195 
     | 
    
         
             
              Browser.prototype.parents = function(page_id, id) {
         
     | 
| 
       194 
     | 
    
         
            -
                return this.sendResponse(this.node(page_id, id).parentIds());
         
     | 
| 
      
 196 
     | 
    
         
            +
                return this.current_command.sendResponse(this.node(page_id, id).parentIds());
         
     | 
| 
       195 
197 
     | 
    
         
             
              };
         
     | 
| 
       196 
198 
     | 
    
         | 
| 
       197 
199 
     | 
    
         
             
              Browser.prototype.value = function(page_id, id) {
         
     | 
| 
       198 
     | 
    
         
            -
                return this.sendResponse(this.node(page_id, id).value());
         
     | 
| 
      
 200 
     | 
    
         
            +
                return this.current_command.sendResponse(this.node(page_id, id).value());
         
     | 
| 
       199 
201 
     | 
    
         
             
              };
         
     | 
| 
       200 
202 
     | 
    
         | 
| 
       201 
203 
     | 
    
         
             
              Browser.prototype.set = function(page_id, id, value) {
         
     | 
| 
       202 
204 
     | 
    
         
             
                this.node(page_id, id).set(value);
         
     | 
| 
       203 
     | 
    
         
            -
                return this.sendResponse(true);
         
     | 
| 
      
 205 
     | 
    
         
            +
                return this.current_command.sendResponse(true);
         
     | 
| 
       204 
206 
     | 
    
         
             
              };
         
     | 
| 
       205 
207 
     | 
    
         | 
| 
       206 
208 
     | 
    
         
             
              Browser.prototype.select_file = function(page_id, id, value) {
         
     | 
| 
         @@ -209,72 +211,91 @@ Poltergeist.Browser = (function() { 
     | 
|
| 
       209 
211 
     | 
    
         
             
                this.currentPage.beforeUpload(node.id);
         
     | 
| 
       210 
212 
     | 
    
         
             
                this.currentPage.uploadFile('[_poltergeist_selected]', value);
         
     | 
| 
       211 
213 
     | 
    
         
             
                this.currentPage.afterUpload(node.id);
         
     | 
| 
       212 
     | 
    
         
            -
                 
     | 
| 
      
 214 
     | 
    
         
            +
                if (phantom.version.major === 2) {
         
     | 
| 
      
 215 
     | 
    
         
            +
                  return this.click(page_id, id);
         
     | 
| 
      
 216 
     | 
    
         
            +
                } else {
         
     | 
| 
      
 217 
     | 
    
         
            +
                  return this.current_command.sendResponse(true);
         
     | 
| 
      
 218 
     | 
    
         
            +
                }
         
     | 
| 
       213 
219 
     | 
    
         
             
              };
         
     | 
| 
       214 
220 
     | 
    
         | 
| 
       215 
221 
     | 
    
         
             
              Browser.prototype.select = function(page_id, id, value) {
         
     | 
| 
       216 
     | 
    
         
            -
                return this.sendResponse(this.node(page_id, id).select(value));
         
     | 
| 
      
 222 
     | 
    
         
            +
                return this.current_command.sendResponse(this.node(page_id, id).select(value));
         
     | 
| 
       217 
223 
     | 
    
         
             
              };
         
     | 
| 
       218 
224 
     | 
    
         | 
| 
       219 
225 
     | 
    
         
             
              Browser.prototype.tag_name = function(page_id, id) {
         
     | 
| 
       220 
     | 
    
         
            -
                return this.sendResponse(this.node(page_id, id).tagName());
         
     | 
| 
      
 226 
     | 
    
         
            +
                return this.current_command.sendResponse(this.node(page_id, id).tagName());
         
     | 
| 
       221 
227 
     | 
    
         
             
              };
         
     | 
| 
       222 
228 
     | 
    
         | 
| 
       223 
229 
     | 
    
         
             
              Browser.prototype.visible = function(page_id, id) {
         
     | 
| 
       224 
     | 
    
         
            -
                return this.sendResponse(this.node(page_id, id).isVisible());
         
     | 
| 
      
 230 
     | 
    
         
            +
                return this.current_command.sendResponse(this.node(page_id, id).isVisible());
         
     | 
| 
       225 
231 
     | 
    
         
             
              };
         
     | 
| 
       226 
232 
     | 
    
         | 
| 
       227 
233 
     | 
    
         
             
              Browser.prototype.disabled = function(page_id, id) {
         
     | 
| 
       228 
     | 
    
         
            -
                return this.sendResponse(this.node(page_id, id).isDisabled());
         
     | 
| 
      
 234 
     | 
    
         
            +
                return this.current_command.sendResponse(this.node(page_id, id).isDisabled());
         
     | 
| 
       229 
235 
     | 
    
         
             
              };
         
     | 
| 
       230 
236 
     | 
    
         | 
| 
       231 
237 
     | 
    
         
             
              Browser.prototype.path = function(page_id, id) {
         
     | 
| 
       232 
     | 
    
         
            -
                return this.sendResponse(this.node(page_id, id).path());
         
     | 
| 
      
 238 
     | 
    
         
            +
                return this.current_command.sendResponse(this.node(page_id, id).path());
         
     | 
| 
       233 
239 
     | 
    
         
             
              };
         
     | 
| 
       234 
240 
     | 
    
         | 
| 
       235 
241 
     | 
    
         
             
              Browser.prototype.evaluate = function(script) {
         
     | 
| 
       236 
     | 
    
         
            -
                return this.sendResponse(this.currentPage.evaluate("function() { return " + script + " }"));
         
     | 
| 
      
 242 
     | 
    
         
            +
                return this.current_command.sendResponse(this.currentPage.evaluate("function() { return " + script + " }"));
         
     | 
| 
       237 
243 
     | 
    
         
             
              };
         
     | 
| 
       238 
244 
     | 
    
         | 
| 
       239 
245 
     | 
    
         
             
              Browser.prototype.execute = function(script) {
         
     | 
| 
       240 
246 
     | 
    
         
             
                this.currentPage.execute("function() { " + script + " }");
         
     | 
| 
       241 
     | 
    
         
            -
                return this.sendResponse(true);
         
     | 
| 
      
 247 
     | 
    
         
            +
                return this.current_command.sendResponse(true);
         
     | 
| 
       242 
248 
     | 
    
         
             
              };
         
     | 
| 
       243 
249 
     | 
    
         | 
| 
       244 
250 
     | 
    
         
             
              Browser.prototype.frameUrl = function(frame_name) {
         
     | 
| 
       245 
251 
     | 
    
         
             
                return this.currentPage.frameUrl(frame_name);
         
     | 
| 
       246 
252 
     | 
    
         
             
              };
         
     | 
| 
       247 
253 
     | 
    
         | 
| 
       248 
     | 
    
         
            -
              Browser.prototype. 
     | 
| 
       249 
     | 
    
         
            -
                var  
     | 
| 
       250 
     | 
    
         
            -
             
     | 
| 
       251 
     | 
    
         
            -
             
     | 
| 
       252 
     | 
    
         
            -
                   
     | 
| 
      
 254 
     | 
    
         
            +
              Browser.prototype.pushFrame = function(command, name, timeout) {
         
     | 
| 
      
 255 
     | 
    
         
            +
                var frame, ref;
         
     | 
| 
      
 256 
     | 
    
         
            +
                if (Array.isArray(name)) {
         
     | 
| 
      
 257 
     | 
    
         
            +
                  frame = this.node.apply(this, name);
         
     | 
| 
      
 258 
     | 
    
         
            +
                  name = frame.getAttribute('name') || frame.getAttribute('id');
         
     | 
| 
      
 259 
     | 
    
         
            +
                  if (!name) {
         
     | 
| 
      
 260 
     | 
    
         
            +
                    frame.setAttribute('name', "_random_name_" + (new Date().getTime()));
         
     | 
| 
      
 261 
     | 
    
         
            +
                    name = frame.getAttribute('name');
         
     | 
| 
      
 262 
     | 
    
         
            +
                  }
         
     | 
| 
       253 
263 
     | 
    
         
             
                }
         
     | 
| 
       254 
     | 
    
         
            -
                if ( 
     | 
| 
       255 
     | 
    
         
            -
                  return  
     | 
| 
      
 264 
     | 
    
         
            +
                if (ref = this.frameUrl(name), indexOf.call(this.currentPage.blockedUrls(), ref) >= 0) {
         
     | 
| 
      
 265 
     | 
    
         
            +
                  return command.sendResponse(true);
         
     | 
| 
       256 
266 
     | 
    
         
             
                } else if (this.currentPage.pushFrame(name)) {
         
     | 
| 
       257 
267 
     | 
    
         
             
                  if (this.currentPage.currentUrl() === 'about:blank') {
         
     | 
| 
       258 
268 
     | 
    
         
             
                    this.currentPage.state = 'awaiting_frame_load';
         
     | 
| 
       259 
     | 
    
         
            -
                    return this.currentPage.waitState('default', function() {
         
     | 
| 
       260 
     | 
    
         
            -
                      return  
     | 
| 
       261 
     | 
    
         
            -
             
     | 
| 
      
 269 
     | 
    
         
            +
                    return this.currentPage.waitState('default', (function(_this) {
         
     | 
| 
      
 270 
     | 
    
         
            +
                      return function() {
         
     | 
| 
      
 271 
     | 
    
         
            +
                        return command.sendResponse(true);
         
     | 
| 
      
 272 
     | 
    
         
            +
                      };
         
     | 
| 
      
 273 
     | 
    
         
            +
                    })(this));
         
     | 
| 
       262 
274 
     | 
    
         
             
                  } else {
         
     | 
| 
       263 
     | 
    
         
            -
                    return  
     | 
| 
      
 275 
     | 
    
         
            +
                    return command.sendResponse(true);
         
     | 
| 
       264 
276 
     | 
    
         
             
                  }
         
     | 
| 
       265 
277 
     | 
    
         
             
                } else {
         
     | 
| 
       266 
278 
     | 
    
         
             
                  if (new Date().getTime() < timeout) {
         
     | 
| 
       267 
     | 
    
         
            -
                    return setTimeout((function() {
         
     | 
| 
       268 
     | 
    
         
            -
                      return  
     | 
| 
       269 
     | 
    
         
            -
             
     | 
| 
      
 279 
     | 
    
         
            +
                    return setTimeout(((function(_this) {
         
     | 
| 
      
 280 
     | 
    
         
            +
                      return function() {
         
     | 
| 
      
 281 
     | 
    
         
            +
                        return _this.pushFrame(command, name, timeout);
         
     | 
| 
      
 282 
     | 
    
         
            +
                      };
         
     | 
| 
      
 283 
     | 
    
         
            +
                    })(this)), 50);
         
     | 
| 
       270 
284 
     | 
    
         
             
                  } else {
         
     | 
| 
       271 
     | 
    
         
            -
                    return  
     | 
| 
      
 285 
     | 
    
         
            +
                    return command.sendError(new Poltergeist.FrameNotFound(name));
         
     | 
| 
       272 
286 
     | 
    
         
             
                  }
         
     | 
| 
       273 
287 
     | 
    
         
             
                }
         
     | 
| 
       274 
288 
     | 
    
         
             
              };
         
     | 
| 
       275 
289 
     | 
    
         | 
| 
      
 290 
     | 
    
         
            +
              Browser.prototype.push_frame = function(name, timeout) {
         
     | 
| 
      
 291 
     | 
    
         
            +
                if (timeout == null) {
         
     | 
| 
      
 292 
     | 
    
         
            +
                  timeout = (new Date().getTime()) + 2000;
         
     | 
| 
      
 293 
     | 
    
         
            +
                }
         
     | 
| 
      
 294 
     | 
    
         
            +
                return this.pushFrame(this.current_command, name, timeout);
         
     | 
| 
      
 295 
     | 
    
         
            +
              };
         
     | 
| 
      
 296 
     | 
    
         
            +
             
     | 
| 
       276 
297 
     | 
    
         
             
              Browser.prototype.pop_frame = function() {
         
     | 
| 
       277 
     | 
    
         
            -
                return this.sendResponse(this.currentPage.popFrame());
         
     | 
| 
      
 298 
     | 
    
         
            +
                return this.current_command.sendResponse(this.currentPage.popFrame());
         
     | 
| 
       278 
299 
     | 
    
         
             
              };
         
     | 
| 
       279 
300 
     | 
    
         | 
| 
       280 
301 
     | 
    
         
             
              Browser.prototype.window_handles = function() {
         
     | 
| 
         @@ -284,7 +305,7 @@ Poltergeist.Browser = (function() { 
     | 
|
| 
       284 
305 
     | 
    
         
             
                }).map(function(p) {
         
     | 
| 
       285 
306 
     | 
    
         
             
                  return p.handle;
         
     | 
| 
       286 
307 
     | 
    
         
             
                });
         
     | 
| 
       287 
     | 
    
         
            -
                return this.sendResponse(handles);
         
     | 
| 
      
 308 
     | 
    
         
            +
                return this.current_command.sendResponse(handles);
         
     | 
| 
       288 
309 
     | 
    
         
             
              };
         
     | 
| 
       289 
310 
     | 
    
         | 
| 
       290 
311 
     | 
    
         
             
              Browser.prototype.window_handle = function(name) {
         
     | 
| 
         @@ -295,21 +316,23 @@ Poltergeist.Browser = (function() { 
     | 
|
| 
       295 
316 
     | 
    
         
             
                handle = name ? (page = this.pages.filter(function(p) {
         
     | 
| 
       296 
317 
     | 
    
         
             
                  return !p.closed && p.windowName() === name;
         
     | 
| 
       297 
318 
     | 
    
         
             
                })[0], page ? page.handle : null) : this.currentPage.handle;
         
     | 
| 
       298 
     | 
    
         
            -
                return this.sendResponse(handle);
         
     | 
| 
      
 319 
     | 
    
         
            +
                return this.current_command.sendResponse(handle);
         
     | 
| 
       299 
320 
     | 
    
         
             
              };
         
     | 
| 
       300 
321 
     | 
    
         | 
| 
       301 
322 
     | 
    
         
             
              Browser.prototype.switch_to_window = function(handle) {
         
     | 
| 
       302 
     | 
    
         
            -
                var page 
     | 
| 
       303 
     | 
    
         
            -
             
     | 
| 
      
 323 
     | 
    
         
            +
                var command, page;
         
     | 
| 
      
 324 
     | 
    
         
            +
                command = this.current_command;
         
     | 
| 
       304 
325 
     | 
    
         
             
                page = this.getPageByHandle(handle);
         
     | 
| 
       305 
326 
     | 
    
         
             
                if (page) {
         
     | 
| 
       306 
327 
     | 
    
         
             
                  if (page !== this.currentPage) {
         
     | 
| 
       307 
     | 
    
         
            -
                    return page.waitState('default', function() {
         
     | 
| 
       308 
     | 
    
         
            -
                       
     | 
| 
       309 
     | 
    
         
            -
             
     | 
| 
       310 
     | 
    
         
            -
             
     | 
| 
      
 328 
     | 
    
         
            +
                    return page.waitState('default', (function(_this) {
         
     | 
| 
      
 329 
     | 
    
         
            +
                      return function() {
         
     | 
| 
      
 330 
     | 
    
         
            +
                        _this.currentPage = page;
         
     | 
| 
      
 331 
     | 
    
         
            +
                        return command.sendResponse(true);
         
     | 
| 
      
 332 
     | 
    
         
            +
                      };
         
     | 
| 
      
 333 
     | 
    
         
            +
                    })(this));
         
     | 
| 
       311 
334 
     | 
    
         
             
                  } else {
         
     | 
| 
       312 
     | 
    
         
            -
                    return  
     | 
| 
      
 335 
     | 
    
         
            +
                    return command.sendResponse(true);
         
     | 
| 
       313 
336 
     | 
    
         
             
                  }
         
     | 
| 
       314 
337 
     | 
    
         
             
                } else {
         
     | 
| 
       315 
338 
     | 
    
         
             
                  throw new Poltergeist.NoSuchWindowError;
         
     | 
| 
         @@ -318,7 +341,7 @@ Poltergeist.Browser = (function() { 
     | 
|
| 
       318 
341 
     | 
    
         | 
| 
       319 
342 
     | 
    
         
             
              Browser.prototype.open_new_window = function() {
         
     | 
| 
       320 
343 
     | 
    
         
             
                this.execute('window.open()');
         
     | 
| 
       321 
     | 
    
         
            -
                return this.sendResponse(true);
         
     | 
| 
      
 344 
     | 
    
         
            +
                return this.current_command.sendResponse(true);
         
     | 
| 
       322 
345 
     | 
    
         
             
              };
         
     | 
| 
       323 
346 
     | 
    
         | 
| 
       324 
347 
     | 
    
         
             
              Browser.prototype.close_window = function(handle) {
         
     | 
| 
         @@ -326,32 +349,34 @@ Poltergeist.Browser = (function() { 
     | 
|
| 
       326 
349 
     | 
    
         
             
                page = this.getPageByHandle(handle);
         
     | 
| 
       327 
350 
     | 
    
         
             
                if (page) {
         
     | 
| 
       328 
351 
     | 
    
         
             
                  page.release();
         
     | 
| 
       329 
     | 
    
         
            -
                  return this.sendResponse(true);
         
     | 
| 
      
 352 
     | 
    
         
            +
                  return this.current_command.sendResponse(true);
         
     | 
| 
       330 
353 
     | 
    
         
             
                } else {
         
     | 
| 
       331 
     | 
    
         
            -
                  return this.sendResponse(false);
         
     | 
| 
      
 354 
     | 
    
         
            +
                  return this.current_command.sendResponse(false);
         
     | 
| 
       332 
355 
     | 
    
         
             
                }
         
     | 
| 
       333 
356 
     | 
    
         
             
              };
         
     | 
| 
       334 
357 
     | 
    
         | 
| 
       335 
358 
     | 
    
         
             
              Browser.prototype.mouse_event = function(page_id, id, name) {
         
     | 
| 
       336 
     | 
    
         
            -
                var node 
     | 
| 
       337 
     | 
    
         
            -
                  _this = this;
         
     | 
| 
      
 359 
     | 
    
         
            +
                var command, node;
         
     | 
| 
       338 
360 
     | 
    
         
             
                node = this.node(page_id, id);
         
     | 
| 
       339 
361 
     | 
    
         
             
                this.currentPage.state = 'mouse_event';
         
     | 
| 
       340 
362 
     | 
    
         
             
                this.last_mouse_event = node.mouseEvent(name);
         
     | 
| 
       341 
     | 
    
         
            -
                 
     | 
| 
       342 
     | 
    
         
            -
             
     | 
| 
       343 
     | 
    
         
            -
             
     | 
| 
       344 
     | 
    
         
            -
                     
     | 
| 
       345 
     | 
    
         
            -
                       
     | 
| 
       346 
     | 
    
         
            -
             
     | 
| 
       347 
     | 
    
         
            -
                  } else {
         
     | 
| 
       348 
     | 
    
         
            -
                    return _this.currentPage.waitState('default', function() {
         
     | 
| 
       349 
     | 
    
         
            -
                      return _this.sendResponse({
         
     | 
| 
      
 363 
     | 
    
         
            +
                command = this.current_command;
         
     | 
| 
      
 364 
     | 
    
         
            +
                return setTimeout((function(_this) {
         
     | 
| 
      
 365 
     | 
    
         
            +
                  return function() {
         
     | 
| 
      
 366 
     | 
    
         
            +
                    if (_this.currentPage.state === 'mouse_event') {
         
     | 
| 
      
 367 
     | 
    
         
            +
                      _this.currentPage.state = 'default';
         
     | 
| 
      
 368 
     | 
    
         
            +
                      return command.sendResponse({
         
     | 
| 
       350 
369 
     | 
    
         
             
                        position: _this.last_mouse_event
         
     | 
| 
       351 
370 
     | 
    
         
             
                      });
         
     | 
| 
       352 
     | 
    
         
            -
                    } 
     | 
| 
       353 
     | 
    
         
            -
             
     | 
| 
       354 
     | 
    
         
            -
             
     | 
| 
      
 371 
     | 
    
         
            +
                    } else {
         
     | 
| 
      
 372 
     | 
    
         
            +
                      return _this.currentPage.waitState('default', function() {
         
     | 
| 
      
 373 
     | 
    
         
            +
                        return command.sendResponse({
         
     | 
| 
      
 374 
     | 
    
         
            +
                          position: _this.last_mouse_event
         
     | 
| 
      
 375 
     | 
    
         
            +
                        });
         
     | 
| 
      
 376 
     | 
    
         
            +
                      });
         
     | 
| 
      
 377 
     | 
    
         
            +
                    }
         
     | 
| 
      
 378 
     | 
    
         
            +
                  };
         
     | 
| 
      
 379 
     | 
    
         
            +
                })(this), 5);
         
     | 
| 
       355 
380 
     | 
    
         
             
              };
         
     | 
| 
       356 
381 
     | 
    
         | 
| 
       357 
382 
     | 
    
         
             
              Browser.prototype.click = function(page_id, id) {
         
     | 
| 
         @@ -372,7 +397,7 @@ Poltergeist.Browser = (function() { 
     | 
|
| 
       372 
397 
     | 
    
         | 
| 
       373 
398 
     | 
    
         
             
              Browser.prototype.click_coordinates = function(x, y) {
         
     | 
| 
       374 
399 
     | 
    
         
             
                this.currentPage.sendEvent('click', x, y);
         
     | 
| 
       375 
     | 
    
         
            -
                return this.sendResponse({
         
     | 
| 
      
 400 
     | 
    
         
            +
                return this.current_command.sendResponse({
         
     | 
| 
       376 
401 
     | 
    
         
             
                  click: {
         
     | 
| 
       377 
402 
     | 
    
         
             
                    x: x,
         
     | 
| 
       378 
403 
     | 
    
         
             
                    y: y
         
     | 
| 
         @@ -382,26 +407,26 @@ Poltergeist.Browser = (function() { 
     | 
|
| 
       382 
407 
     | 
    
         | 
| 
       383 
408 
     | 
    
         
             
              Browser.prototype.drag = function(page_id, id, other_id) {
         
     | 
| 
       384 
409 
     | 
    
         
             
                this.node(page_id, id).dragTo(this.node(page_id, other_id));
         
     | 
| 
       385 
     | 
    
         
            -
                return this.sendResponse(true);
         
     | 
| 
      
 410 
     | 
    
         
            +
                return this.current_command.sendResponse(true);
         
     | 
| 
       386 
411 
     | 
    
         
             
              };
         
     | 
| 
       387 
412 
     | 
    
         | 
| 
       388 
413 
     | 
    
         
             
              Browser.prototype.drag_by = function(page_id, id, x, y) {
         
     | 
| 
       389 
414 
     | 
    
         
             
                this.node(page_id, id).dragBy(x, y);
         
     | 
| 
       390 
     | 
    
         
            -
                return this.sendResponse(true);
         
     | 
| 
      
 415 
     | 
    
         
            +
                return this.current_command.sendResponse(true);
         
     | 
| 
       391 
416 
     | 
    
         
             
              };
         
     | 
| 
       392 
417 
     | 
    
         | 
| 
       393 
418 
     | 
    
         
             
              Browser.prototype.trigger = function(page_id, id, event) {
         
     | 
| 
       394 
419 
     | 
    
         
             
                this.node(page_id, id).trigger(event);
         
     | 
| 
       395 
     | 
    
         
            -
                return this.sendResponse(event);
         
     | 
| 
      
 420 
     | 
    
         
            +
                return this.current_command.sendResponse(event);
         
     | 
| 
       396 
421 
     | 
    
         
             
              };
         
     | 
| 
       397 
422 
     | 
    
         | 
| 
       398 
423 
     | 
    
         
             
              Browser.prototype.equals = function(page_id, id, other_id) {
         
     | 
| 
       399 
     | 
    
         
            -
                return this.sendResponse(this.node(page_id, id).isEqual(this.node(page_id, other_id)));
         
     | 
| 
      
 424 
     | 
    
         
            +
                return this.current_command.sendResponse(this.node(page_id, id).isEqual(this.node(page_id, other_id)));
         
     | 
| 
       400 
425 
     | 
    
         
             
              };
         
     | 
| 
       401 
426 
     | 
    
         | 
| 
       402 
427 
     | 
    
         
             
              Browser.prototype.reset = function() {
         
     | 
| 
       403 
428 
     | 
    
         
             
                this.resetPage();
         
     | 
| 
       404 
     | 
    
         
            -
                return this.sendResponse(true);
         
     | 
| 
      
 429 
     | 
    
         
            +
                return this.current_command.sendResponse(true);
         
     | 
| 
       405 
430 
     | 
    
         
             
              };
         
     | 
| 
       406 
431 
     | 
    
         | 
| 
       407 
432 
     | 
    
         
             
              Browser.prototype.scroll_to = function(left, top) {
         
     | 
| 
         @@ -409,35 +434,35 @@ Poltergeist.Browser = (function() { 
     | 
|
| 
       409 
434 
     | 
    
         
             
                  left: left,
         
     | 
| 
       410 
435 
     | 
    
         
             
                  top: top
         
     | 
| 
       411 
436 
     | 
    
         
             
                });
         
     | 
| 
       412 
     | 
    
         
            -
                return this.sendResponse(true);
         
     | 
| 
      
 437 
     | 
    
         
            +
                return this.current_command.sendResponse(true);
         
     | 
| 
       413 
438 
     | 
    
         
             
              };
         
     | 
| 
       414 
439 
     | 
    
         | 
| 
       415 
440 
     | 
    
         
             
              Browser.prototype.send_keys = function(page_id, id, keys) {
         
     | 
| 
       416 
     | 
    
         
            -
                var  
     | 
| 
      
 441 
     | 
    
         
            +
                var i, j, k, key, len, len1, len2, modifier_code, modifier_key, modifier_keys, sequence, target;
         
     | 
| 
       417 
442 
     | 
    
         
             
                target = this.node(page_id, id);
         
     | 
| 
       418 
443 
     | 
    
         
             
                if (!target.containsSelection()) {
         
     | 
| 
       419 
444 
     | 
    
         
             
                  target.mouseEvent('click');
         
     | 
| 
       420 
445 
     | 
    
         
             
                }
         
     | 
| 
       421 
     | 
    
         
            -
                for ( 
     | 
| 
       422 
     | 
    
         
            -
                  sequence = keys[ 
     | 
| 
      
 446 
     | 
    
         
            +
                for (i = 0, len = keys.length; i < len; i++) {
         
     | 
| 
      
 447 
     | 
    
         
            +
                  sequence = keys[i];
         
     | 
| 
       423 
448 
     | 
    
         
             
                  key = sequence.key != null ? this.currentPage.keyCode(sequence.key) : sequence;
         
     | 
| 
       424 
449 
     | 
    
         
             
                  if (sequence.modifier != null) {
         
     | 
| 
       425 
450 
     | 
    
         
             
                    modifier_keys = this.currentPage.keyModifierKeys(sequence.modifier);
         
     | 
| 
       426 
451 
     | 
    
         
             
                    modifier_code = this.currentPage.keyModifierCode(sequence.modifier);
         
     | 
| 
       427 
     | 
    
         
            -
                    for ( 
     | 
| 
       428 
     | 
    
         
            -
                      modifier_key = modifier_keys[ 
     | 
| 
      
 452 
     | 
    
         
            +
                    for (j = 0, len1 = modifier_keys.length; j < len1; j++) {
         
     | 
| 
      
 453 
     | 
    
         
            +
                      modifier_key = modifier_keys[j];
         
     | 
| 
       429 
454 
     | 
    
         
             
                      this.currentPage.sendEvent('keydown', modifier_key);
         
     | 
| 
       430 
455 
     | 
    
         
             
                    }
         
     | 
| 
       431 
456 
     | 
    
         
             
                    this.currentPage.sendEvent('keypress', key, null, null, modifier_code);
         
     | 
| 
       432 
     | 
    
         
            -
                    for ( 
     | 
| 
       433 
     | 
    
         
            -
                      modifier_key = modifier_keys[ 
     | 
| 
      
 457 
     | 
    
         
            +
                    for (k = 0, len2 = modifier_keys.length; k < len2; k++) {
         
     | 
| 
      
 458 
     | 
    
         
            +
                      modifier_key = modifier_keys[k];
         
     | 
| 
       434 
459 
     | 
    
         
             
                      this.currentPage.sendEvent('keyup', modifier_key);
         
     | 
| 
       435 
460 
     | 
    
         
             
                    }
         
     | 
| 
       436 
461 
     | 
    
         
             
                  } else {
         
     | 
| 
       437 
462 
     | 
    
         
             
                    this.currentPage.sendEvent('keypress', key);
         
     | 
| 
       438 
463 
     | 
    
         
             
                  }
         
     | 
| 
       439 
464 
     | 
    
         
             
                }
         
     | 
| 
       440 
     | 
    
         
            -
                return this.sendResponse(true);
         
     | 
| 
      
 465 
     | 
    
         
            +
                return this.current_command.sendResponse(true);
         
     | 
| 
       441 
466 
     | 
    
         
             
              };
         
     | 
| 
       442 
467 
     | 
    
         | 
| 
       443 
468 
     | 
    
         
             
              Browser.prototype.render_base64 = function(format, full, selector) {
         
     | 
| 
         @@ -447,7 +472,7 @@ Poltergeist.Browser = (function() { 
     | 
|
| 
       447 
472 
     | 
    
         
             
                }
         
     | 
| 
       448 
473 
     | 
    
         
             
                this.set_clip_rect(full, selector);
         
     | 
| 
       449 
474 
     | 
    
         
             
                encoded_image = this.currentPage.renderBase64(format);
         
     | 
| 
       450 
     | 
    
         
            -
                return this.sendResponse(encoded_image);
         
     | 
| 
      
 475 
     | 
    
         
            +
                return this.current_command.sendResponse(encoded_image);
         
     | 
| 
       451 
476 
     | 
    
         
             
              };
         
     | 
| 
       452 
477 
     | 
    
         | 
| 
       453 
478 
     | 
    
         
             
              Browser.prototype.render = function(path, full, selector) {
         
     | 
| 
         @@ -465,13 +490,13 @@ Poltergeist.Browser = (function() { 
     | 
|
| 
       465 
490 
     | 
    
         
             
                  left: dimensions.left,
         
     | 
| 
       466 
491 
     | 
    
         
             
                  top: dimensions.top
         
     | 
| 
       467 
492 
     | 
    
         
             
                });
         
     | 
| 
       468 
     | 
    
         
            -
                return this.sendResponse(true);
         
     | 
| 
      
 493 
     | 
    
         
            +
                return this.current_command.sendResponse(true);
         
     | 
| 
       469 
494 
     | 
    
         
             
              };
         
     | 
| 
       470 
495 
     | 
    
         | 
| 
       471 
496 
     | 
    
         
             
              Browser.prototype.set_clip_rect = function(full, selector) {
         
     | 
| 
       472 
     | 
    
         
            -
                var dimensions, document, rect,  
     | 
| 
      
 497 
     | 
    
         
            +
                var dimensions, document, rect, ref, viewport;
         
     | 
| 
       473 
498 
     | 
    
         
             
                dimensions = this.currentPage.validatedDimensions();
         
     | 
| 
       474 
     | 
    
         
            -
                 
     | 
| 
      
 499 
     | 
    
         
            +
                ref = [dimensions.document, dimensions.viewport], document = ref[0], viewport = ref[1];
         
     | 
| 
       475 
500 
     | 
    
         
             
                rect = full ? {
         
     | 
| 
       476 
501 
     | 
    
         
             
                  left: 0,
         
     | 
| 
       477 
502 
     | 
    
         
             
                  top: 0,
         
     | 
| 
         @@ -489,12 +514,12 @@ Poltergeist.Browser = (function() { 
     | 
|
| 
       489 
514 
     | 
    
         | 
| 
       490 
515 
     | 
    
         
             
              Browser.prototype.set_paper_size = function(size) {
         
     | 
| 
       491 
516 
     | 
    
         
             
                this.currentPage.setPaperSize(size);
         
     | 
| 
       492 
     | 
    
         
            -
                return this.sendResponse(true);
         
     | 
| 
      
 517 
     | 
    
         
            +
                return this.current_command.sendResponse(true);
         
     | 
| 
       493 
518 
     | 
    
         
             
              };
         
     | 
| 
       494 
519 
     | 
    
         | 
| 
       495 
520 
     | 
    
         
             
              Browser.prototype.set_zoom_factor = function(zoom_factor) {
         
     | 
| 
       496 
521 
     | 
    
         
             
                this.currentPage.setZoomFactor(zoom_factor);
         
     | 
| 
       497 
     | 
    
         
            -
                return this.sendResponse(true);
         
     | 
| 
      
 522 
     | 
    
         
            +
                return this.current_command.sendResponse(true);
         
     | 
| 
       498 
523 
     | 
    
         
             
              };
         
     | 
| 
       499 
524 
     | 
    
         | 
| 
       500 
525 
     | 
    
         
             
              Browser.prototype.resize = function(width, height) {
         
     | 
| 
         @@ -502,20 +527,20 @@ Poltergeist.Browser = (function() { 
     | 
|
| 
       502 
527 
     | 
    
         
             
                  width: width,
         
     | 
| 
       503 
528 
     | 
    
         
             
                  height: height
         
     | 
| 
       504 
529 
     | 
    
         
             
                });
         
     | 
| 
       505 
     | 
    
         
            -
                return this.sendResponse(true);
         
     | 
| 
      
 530 
     | 
    
         
            +
                return this.current_command.sendResponse(true);
         
     | 
| 
       506 
531 
     | 
    
         
             
              };
         
     | 
| 
       507 
532 
     | 
    
         | 
| 
       508 
533 
     | 
    
         
             
              Browser.prototype.network_traffic = function() {
         
     | 
| 
       509 
     | 
    
         
            -
                return this.sendResponse(this.currentPage.networkTraffic());
         
     | 
| 
      
 534 
     | 
    
         
            +
                return this.current_command.sendResponse(this.currentPage.networkTraffic());
         
     | 
| 
       510 
535 
     | 
    
         
             
              };
         
     | 
| 
       511 
536 
     | 
    
         | 
| 
       512 
537 
     | 
    
         
             
              Browser.prototype.clear_network_traffic = function() {
         
     | 
| 
       513 
538 
     | 
    
         
             
                this.currentPage.clearNetworkTraffic();
         
     | 
| 
       514 
     | 
    
         
            -
                return this.sendResponse(true);
         
     | 
| 
      
 539 
     | 
    
         
            +
                return this.current_command.sendResponse(true);
         
     | 
| 
       515 
540 
     | 
    
         
             
              };
         
     | 
| 
       516 
541 
     | 
    
         | 
| 
       517 
542 
     | 
    
         
             
              Browser.prototype.get_headers = function() {
         
     | 
| 
       518 
     | 
    
         
            -
                return this.sendResponse(this.currentPage.getCustomHeaders());
         
     | 
| 
      
 543 
     | 
    
         
            +
                return this.current_command.sendResponse(this.currentPage.getCustomHeaders());
         
     | 
| 
       519 
544 
     | 
    
         
             
              };
         
     | 
| 
       520 
545 
     | 
    
         | 
| 
       521 
546 
     | 
    
         
             
              Browser.prototype.set_headers = function(headers) {
         
     | 
| 
         @@ -523,7 +548,7 @@ Poltergeist.Browser = (function() { 
     | 
|
| 
       523 
548 
     | 
    
         
             
                  this.currentPage.setUserAgent(headers['User-Agent']);
         
     | 
| 
       524 
549 
     | 
    
         
             
                }
         
     | 
| 
       525 
550 
     | 
    
         
             
                this.currentPage.setCustomHeaders(headers);
         
     | 
| 
       526 
     | 
    
         
            -
                return this.sendResponse(true);
         
     | 
| 
      
 551 
     | 
    
         
            +
                return this.current_command.sendResponse(true);
         
     | 
| 
       527 
552 
     | 
    
         
             
              };
         
     | 
| 
       528 
553 
     | 
    
         | 
| 
       529 
554 
     | 
    
         
             
              Browser.prototype.add_headers = function(headers) {
         
     | 
| 
         @@ -544,46 +569,46 @@ Poltergeist.Browser = (function() { 
     | 
|
| 
       544 
569 
     | 
    
         
             
              };
         
     | 
| 
       545 
570 
     | 
    
         | 
| 
       546 
571 
     | 
    
         
             
              Browser.prototype.response_headers = function() {
         
     | 
| 
       547 
     | 
    
         
            -
                return this.sendResponse(this.currentPage.responseHeaders());
         
     | 
| 
      
 572 
     | 
    
         
            +
                return this.current_command.sendResponse(this.currentPage.responseHeaders());
         
     | 
| 
       548 
573 
     | 
    
         
             
              };
         
     | 
| 
       549 
574 
     | 
    
         | 
| 
       550 
575 
     | 
    
         
             
              Browser.prototype.cookies = function() {
         
     | 
| 
       551 
     | 
    
         
            -
                return this.sendResponse(this.currentPage.cookies());
         
     | 
| 
      
 576 
     | 
    
         
            +
                return this.current_command.sendResponse(this.currentPage.cookies());
         
     | 
| 
       552 
577 
     | 
    
         
             
              };
         
     | 
| 
       553 
578 
     | 
    
         | 
| 
       554 
579 
     | 
    
         
             
              Browser.prototype.set_cookie = function(cookie) {
         
     | 
| 
       555 
580 
     | 
    
         
             
                phantom.addCookie(cookie);
         
     | 
| 
       556 
     | 
    
         
            -
                return this.sendResponse(true);
         
     | 
| 
      
 581 
     | 
    
         
            +
                return this.current_command.sendResponse(true);
         
     | 
| 
       557 
582 
     | 
    
         
             
              };
         
     | 
| 
       558 
583 
     | 
    
         | 
| 
       559 
584 
     | 
    
         
             
              Browser.prototype.remove_cookie = function(name) {
         
     | 
| 
       560 
585 
     | 
    
         
             
                this.currentPage.deleteCookie(name);
         
     | 
| 
       561 
     | 
    
         
            -
                return this.sendResponse(true);
         
     | 
| 
      
 586 
     | 
    
         
            +
                return this.current_command.sendResponse(true);
         
     | 
| 
       562 
587 
     | 
    
         
             
              };
         
     | 
| 
       563 
588 
     | 
    
         | 
| 
       564 
589 
     | 
    
         
             
              Browser.prototype.clear_cookies = function() {
         
     | 
| 
       565 
590 
     | 
    
         
             
                phantom.clearCookies();
         
     | 
| 
       566 
     | 
    
         
            -
                return this.sendResponse(true);
         
     | 
| 
      
 591 
     | 
    
         
            +
                return this.current_command.sendResponse(true);
         
     | 
| 
       567 
592 
     | 
    
         
             
              };
         
     | 
| 
       568 
593 
     | 
    
         | 
| 
       569 
594 
     | 
    
         
             
              Browser.prototype.cookies_enabled = function(flag) {
         
     | 
| 
       570 
595 
     | 
    
         
             
                phantom.cookiesEnabled = flag;
         
     | 
| 
       571 
     | 
    
         
            -
                return this.sendResponse(true);
         
     | 
| 
      
 596 
     | 
    
         
            +
                return this.current_command.sendResponse(true);
         
     | 
| 
       572 
597 
     | 
    
         
             
              };
         
     | 
| 
       573 
598 
     | 
    
         | 
| 
       574 
599 
     | 
    
         
             
              Browser.prototype.set_http_auth = function(user, password) {
         
     | 
| 
       575 
600 
     | 
    
         
             
                this.currentPage.setHttpAuth(user, password);
         
     | 
| 
       576 
     | 
    
         
            -
                return this.sendResponse(true);
         
     | 
| 
      
 601 
     | 
    
         
            +
                return this.current_command.sendResponse(true);
         
     | 
| 
       577 
602 
     | 
    
         
             
              };
         
     | 
| 
       578 
603 
     | 
    
         | 
| 
       579 
604 
     | 
    
         
             
              Browser.prototype.set_js_errors = function(value) {
         
     | 
| 
       580 
605 
     | 
    
         
             
                this.js_errors = value;
         
     | 
| 
       581 
     | 
    
         
            -
                return this.sendResponse(true);
         
     | 
| 
      
 606 
     | 
    
         
            +
                return this.current_command.sendResponse(true);
         
     | 
| 
       582 
607 
     | 
    
         
             
              };
         
     | 
| 
       583 
608 
     | 
    
         | 
| 
       584 
609 
     | 
    
         
             
              Browser.prototype.set_debug = function(value) {
         
     | 
| 
       585 
610 
     | 
    
         
             
                this._debug = value;
         
     | 
| 
       586 
     | 
    
         
            -
                return this.sendResponse(true);
         
     | 
| 
      
 611 
     | 
    
         
            +
                return this.current_command.sendResponse(true);
         
     | 
| 
       587 
612 
     | 
    
         
             
              };
         
     | 
| 
       588 
613 
     | 
    
         | 
| 
       589 
614 
     | 
    
         
             
              Browser.prototype.exit = function() {
         
     | 
| 
         @@ -597,48 +622,54 @@ Poltergeist.Browser = (function() { 
     | 
|
| 
       597 
622 
     | 
    
         
             
              };
         
     | 
| 
       598 
623 
     | 
    
         | 
| 
       599 
624 
     | 
    
         
             
              Browser.prototype.go_back = function() {
         
     | 
| 
       600 
     | 
    
         
            -
                var  
     | 
| 
      
 625 
     | 
    
         
            +
                var command;
         
     | 
| 
      
 626 
     | 
    
         
            +
                command = this.current_command;
         
     | 
| 
       601 
627 
     | 
    
         
             
                if (this.currentPage.canGoBack) {
         
     | 
| 
       602 
628 
     | 
    
         
             
                  this.currentPage.state = 'loading';
         
     | 
| 
       603 
629 
     | 
    
         
             
                  this.currentPage.goBack();
         
     | 
| 
       604 
     | 
    
         
            -
                  return this.currentPage.waitState('default', function() {
         
     | 
| 
       605 
     | 
    
         
            -
                    return  
     | 
| 
       606 
     | 
    
         
            -
             
     | 
| 
      
 630 
     | 
    
         
            +
                  return this.currentPage.waitState('default', (function(_this) {
         
     | 
| 
      
 631 
     | 
    
         
            +
                    return function() {
         
     | 
| 
      
 632 
     | 
    
         
            +
                      return command.sendResponse(true);
         
     | 
| 
      
 633 
     | 
    
         
            +
                    };
         
     | 
| 
      
 634 
     | 
    
         
            +
                  })(this));
         
     | 
| 
       607 
635 
     | 
    
         
             
                } else {
         
     | 
| 
       608 
     | 
    
         
            -
                  return  
     | 
| 
      
 636 
     | 
    
         
            +
                  return command.sendResponse(false);
         
     | 
| 
       609 
637 
     | 
    
         
             
                }
         
     | 
| 
       610 
638 
     | 
    
         
             
              };
         
     | 
| 
       611 
639 
     | 
    
         | 
| 
       612 
640 
     | 
    
         
             
              Browser.prototype.go_forward = function() {
         
     | 
| 
       613 
     | 
    
         
            -
                var  
     | 
| 
      
 641 
     | 
    
         
            +
                var command;
         
     | 
| 
      
 642 
     | 
    
         
            +
                command = this.current_command;
         
     | 
| 
       614 
643 
     | 
    
         
             
                if (this.currentPage.canGoForward) {
         
     | 
| 
       615 
644 
     | 
    
         
             
                  this.currentPage.state = 'loading';
         
     | 
| 
       616 
645 
     | 
    
         
             
                  this.currentPage.goForward();
         
     | 
| 
       617 
     | 
    
         
            -
                  return this.currentPage.waitState('default', function() {
         
     | 
| 
       618 
     | 
    
         
            -
                    return  
     | 
| 
       619 
     | 
    
         
            -
             
     | 
| 
      
 646 
     | 
    
         
            +
                  return this.currentPage.waitState('default', (function(_this) {
         
     | 
| 
      
 647 
     | 
    
         
            +
                    return function() {
         
     | 
| 
      
 648 
     | 
    
         
            +
                      return command.sendResponse(true);
         
     | 
| 
      
 649 
     | 
    
         
            +
                    };
         
     | 
| 
      
 650 
     | 
    
         
            +
                  })(this));
         
     | 
| 
       620 
651 
     | 
    
         
             
                } else {
         
     | 
| 
       621 
     | 
    
         
            -
                  return  
     | 
| 
      
 652 
     | 
    
         
            +
                  return command.sendResponse(false);
         
     | 
| 
       622 
653 
     | 
    
         
             
                }
         
     | 
| 
       623 
654 
     | 
    
         
             
              };
         
     | 
| 
       624 
655 
     | 
    
         | 
| 
       625 
656 
     | 
    
         
             
              Browser.prototype.set_url_blacklist = function() {
         
     | 
| 
       626 
657 
     | 
    
         
             
                this.currentPage.urlBlacklist = Array.prototype.slice.call(arguments);
         
     | 
| 
       627 
     | 
    
         
            -
                return this.sendResponse(true);
         
     | 
| 
      
 658 
     | 
    
         
            +
                return this.current_command.sendResponse(true);
         
     | 
| 
       628 
659 
     | 
    
         
             
              };
         
     | 
| 
       629 
660 
     | 
    
         | 
| 
       630 
661 
     | 
    
         
             
              Browser.prototype.set_confirm_process = function(process) {
         
     | 
| 
       631 
662 
     | 
    
         
             
                this.confirm_processes.push(process);
         
     | 
| 
       632 
     | 
    
         
            -
                return this.sendResponse(true);
         
     | 
| 
      
 663 
     | 
    
         
            +
                return this.current_command.sendResponse(true);
         
     | 
| 
       633 
664 
     | 
    
         
             
              };
         
     | 
| 
       634 
665 
     | 
    
         | 
| 
       635 
666 
     | 
    
         
             
              Browser.prototype.set_prompt_response = function(response) {
         
     | 
| 
       636 
667 
     | 
    
         
             
                this.prompt_responses.push(response);
         
     | 
| 
       637 
     | 
    
         
            -
                return this.sendResponse(true);
         
     | 
| 
      
 668 
     | 
    
         
            +
                return this.current_command.sendResponse(true);
         
     | 
| 
       638 
669 
     | 
    
         
             
              };
         
     | 
| 
       639 
670 
     | 
    
         | 
| 
       640 
671 
     | 
    
         
             
              Browser.prototype.modal_message = function() {
         
     | 
| 
       641 
     | 
    
         
            -
                return this.sendResponse(this.processed_modal_messages.shift());
         
     | 
| 
      
 672 
     | 
    
         
            +
                return this.current_command.sendResponse(this.processed_modal_messages.shift());
         
     | 
| 
       642 
673 
     | 
    
         
             
              };
         
     | 
| 
       643 
674 
     | 
    
         | 
| 
       644 
675 
     | 
    
         
             
              return Browser;
         
     |