function asyncTest(page, timeout, params, action, predicate, callback) {
  var startTime = +(new Date), evalTime = startTime,
      rt_args, ac_args;

  function handletry(err, result) {
    if (err || (result != null && !result.poll)) {
      callback(err, result);
    } else if (evalTime - startTime > timeout) {
      // Note that timeout is measured not from the time
      // of the callback, but the time of the call-in.
      // After a slow callback, we can try one more time.
      throw (new Error('timeout'));
    } else {
      if (result) { console.log(result); }
      setTimeout(retry, 100);
    }
  }
  function retry() {
    evalTime = +(new Date);
    page.evaluate.apply(page, rt_args);
  }
  function handleact(err, result) {
    if (err) {
      callback(err);
    }
    retry();
  }

  rt_args = [ predicate, handletry ];
  ac_args = [ action, handleact ];
  rt_args.push.apply(rt_args, params);
  ac_args.push.apply(ac_args, params);

  if (action) {
    page.evaluate.apply(page, ac_args);
  } else {
    retry();
  }
}
//   of the predicate if there wasn't.
of the predicate if there wasn't.
of the predicate if there wasn ' t .
function asyncTest(page, timeout, params, action, predicate, callback) {
  var startTime = +(new Date), evalTime = startTime,
      rt_args, ac_args;
  function handletry(err, result) {
    if (err || (result != null && !result.poll)) {
      callback(err, result);
    } else if (evalTime - startTime > timeout) {
      throw (new Error('timeout'));
    } else {
      if (result) { console.log(result); }
      setTimeout(retry, 100);
    }
  }
  function retry() {
    evalTime = +(new Date);
    page.evaluate.apply(page, rt_args);
  }
  function handleact(err, result) {
    if (err) {
      callback(err);
    }
    retry();
  }
  rt_args = [ predicate, handletry ];
  ac_args = [ action, handleact ];
  rt_args.push.apply(rt_args, params);
  ac_args.push.apply(ac_args, params);
  if (action) {
    page.evaluate.apply(page, ac_args);
  } else {
    retry();
  }
}
function asyncTest ( page , timeout , params , action , predicate , callback ) { var startTime = + ( new Date ) , evalTime = startTime , rt_args , ac_args ; function handletry ( err , result ) { if ( err || ( result != null && ! result . poll ) ) { callback ( err , result ) ; } else if ( evalTime - startTime > timeout ) { throw ( new Error ( 'timeout' ) ) ; } else { if ( result ) { console . log ( result ) ; } setTimeout ( retry , 100 ) ; } } function retry ( ) { evalTime = + ( new Date ) ; page . evaluate . apply ( page , rt_args ) ; } function handleact ( err , result ) { if ( err ) { callback ( err ) ; } retry ( ) ; } rt_args = [ predicate , handletry ] ; ac_args = [ action , handleact ] ; rt_args . push . apply ( rt_args , params ) ; ac_args . push . apply ( ac_args , params ) ; if ( action ) { page . evaluate . apply ( page , ac_args ) ; } else { retry ( ) ; } }
of the predicate if there wasn't.
of the predicate if there wasn ' t .
// Note that timeout is measured not from the time // of the callback, but the time of the call-in. // After a slow callback, we can try one more time.