code: function chainAndErrorCallback(cb, next) {
      var browser = this;
  
      return function wrapDefault() {
          if (cb) {
              try {
                  cb = errorToExceptionCallback.call(browser, cb);
                  cb.apply(browser, _.toArray(arguments).concat([next]));
              } catch (e) {
                  next(e);
              }
          } else if (next) {
              next.apply(this, arguments);
          }
      };
  }
docs: chain and error trapping. If no callback is present, then next is used as callback, otherwise it is the callback responsability to call next (given as last argument)