function evaluatePage(page, fn) {
	var args =  Array.prototype.slice.call(arguments, 2);
	return this.ready.then(function() {
		var stack;
		page = page || this.page;
		var res = HorsemanPromise.fromCallback(function(done) {
				// Wrap fn to be able to catch exceptions and reject Promise
				stack = HorsemanPromise.reject(new Error('See next line'));
				return page.evaluate(function evaluatePage(fnstr, args) {
					try {
						var fn;
						eval('fn = ' + fnstr);

						var res = fn.apply(this, args); // Call fn with args
						return { res: res };
					} catch (err) {
						return { err: err, iserr: err instanceof Error };
					}
				}, fn.toString(), args, done);
			})
			.then(function handleErrback(args) {
				return stack.catch(function(err) {
					if (args.err) {
						if (args.iserr) {
							var stack = err.stack.split('\n').slice(1);
							// Append Node stack to Phantom stack
							args.err.stack += '\n' + stack.join('\n');
						}
						return HorsemanPromise.reject(args.err);
					}
					return args.res;
				});
			});
		stack.catch(function() {});
		return res;
	});
}
function evaluatePage(page, fn) {
	var args =  Array.prototype.slice.call(arguments, 2);
	return this.ready.then(function() {
		var stack;
		page = page || this.page;
		var res = HorsemanPromise.fromCallback(function(done) {
				// Wrap fn to be able to catch exceptions and reject Promise
				stack = HorsemanPromise.reject(new Error('See next line'));
				return page.evaluate(function evaluatePage(fnstr, args) {
					try {
						var fn;
						eval('fn = ' + fnstr);

						var res = fn.apply(this, args); // Call fn with args
						return { res: res };
					} catch (err) {
						return { err: err, iserr: err instanceof Error };
					}
				}, fn.toString(), args, done);
			})
			.then(function handleErrback(args) {
				return stack.catch(function(err) {
					if (args.err) {
						if (args.iserr) {
							var stack = err.stack.split('\n').slice(1);
							// Append Node stack to Phantom stack
							args.err.stack += '\n' + stack.join('\n');
						}
						return HorsemanPromise.reject(args.err);
					}
					return args.res;
				});
			});
		stack.catch(function() {});
		return res;
	});
}
function evaluatePage ( page , fn ) { var args = Array . prototype . slice . call ( arguments , 2 ) ; return this . ready . then ( function ( ) { var stack ; page = page || this . page ; var res = HorsemanPromise . fromCallback ( function ( done ) { // Wrap fn to be able to catch exceptions and reject Promise stack = HorsemanPromise . reject ( new Error ( 'See next line' ) ) ; return page . evaluate ( function evaluatePage ( fnstr , args ) { try { var fn ; eval ( 'fn = ' + fnstr ) ; var res = fn . apply ( this , args ) ; // Call fn with args return { res : res } ; } catch ( err ) { return { err : err , iserr : err instanceof Error } ; } } , fn . toString ( ) , args , done ) ; } ) . then ( function handleErrback ( args ) { return stack . catch ( function ( err ) { if ( args . err ) { if ( args . iserr ) { var stack = err . stack . split ( '\n' ) . slice ( 1 ) ; // Append Node stack to Phantom stack args . err . stack += '\n' + stack . join ( '\n' ) ; } return HorsemanPromise . reject ( args . err ) ; } return args . res ; } ) ; } ) ; stack . catch ( function ( ) { } ) ; return res ; } ) ; }
Evaluates a function on the given page.
@this Horseman
@param {Page} page
@param {function} fn
@param {...*} [arguments]
Evaluates a function on the given page .