lib/capybara/poltergeist/client/compiled/browser.js in poltergeist-1.16.0 vs lib/capybara/poltergeist/client/compiled/browser.js in poltergeist-1.17.0
- old
+ new
@@ -35,46 +35,51 @@
this.page.handle = "" + (this._counter++);
this.pages.push(this.page);
this.processed_modal_messages = [];
this.confirm_processes = [];
this.prompt_responses = [];
- this.page["native"]().onAlert = (function(_this) {
+ this.setupPageHandlers(this.page);
+ };
+
+ Browser.prototype.setupPageHandlers = function(page) {
+ page["native"]().onAlert = (function(_this) {
return function(msg) {
_this.setModalMessage(msg);
};
})(this);
- this.page["native"]().onConfirm = (function(_this) {
+ page["native"]().onConfirm = (function(_this) {
return function(msg) {
var process;
process = _this.confirm_processes.pop();
if (process === void 0) {
process = true;
}
_this.setModalMessage(msg);
return process;
};
})(this);
- this.page["native"]().onPrompt = (function(_this) {
+ page["native"]().onPrompt = (function(_this) {
return function(msg, defaultVal) {
var response;
response = _this.prompt_responses.pop();
if (response === void 0 || response === false) {
response = defaultVal;
}
_this.setModalMessage(msg);
return response;
};
})(this);
- this.page.onPageCreated = (function(_this) {
+ page.onPageCreated = (function(_this) {
return function(newPage) {
- var page;
- page = new Poltergeist.WebPage(newPage);
- page.handle = "" + (_this._counter++);
- page.urlBlacklist = _this.page.urlBlacklist;
- page.urlWhitelist = _this.page.urlWhitelist;
- page.setViewportSize(_this.page.viewportSize());
- return _this.pages.push(page);
+ var _page;
+ _page = new Poltergeist.WebPage(newPage);
+ _page.handle = "" + (_this._counter++);
+ _page.urlBlacklist = page.urlBlacklist;
+ _page.urlWhitelist = page.urlWhitelist;
+ _page.setViewportSize(page.viewportSize());
+ _this.setupPageHandlers(_page);
+ return _this.pages.push(_page);
};
})(this);
};
Browser.prototype.getPageByHandle = function(handle) {
@@ -262,9 +267,34 @@
throw new Poltergeist.ObsoleteNode;
}
}
}
return this.current_command.sendResponse((ref = this.currentPage).evaluate.apply(ref, ["function() { return " + script + " }"].concat(slice.call(args))));
+ };
+
+ Browser.prototype.evaluate_async = function() {
+ var arg, args, cb, command, i, len, max_wait, ref, script;
+ script = arguments[0], max_wait = arguments[1], args = 3 <= arguments.length ? slice.call(arguments, 2) : [];
+ for (i = 0, len = args.length; i < len; i++) {
+ arg = args[i];
+ if (this._isElementArgument(arg)) {
+ if (arg["ELEMENT"]["page_id"] !== this.currentPage.id) {
+ throw new Poltergeist.ObsoleteNode;
+ }
+ }
+ }
+ command = this.current_command;
+ cb = (function(_this) {
+ return function(result) {
+ return command.sendResponse(result);
+ };
+ })(this);
+ (ref = this.currentPage).evaluate_async.apply(ref, ["function() { " + script + " }", cb].concat(slice.call(args)));
+ return setTimeout((function(_this) {
+ return function() {
+ return command.sendError(new Poltergeist.ScriptTimeoutError);
+ };
+ })(this), max_wait * 1000);
};
Browser.prototype.execute = function() {
var arg, args, i, len, ref, script;
script = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];