lib/capybara/poltergeist/client/compiled/browser.js in poltergeist-1.17.0 vs lib/capybara/poltergeist/client/compiled/browser.js in poltergeist-1.18.0
- old
+ new
@@ -7,10 +7,11 @@
this.height = height || 768;
this.pages = [];
this.js_errors = true;
this._debug = false;
this._counter = 0;
+ this._page_settings = null;
this.processed_modal_messages = [];
this.confirm_processes = [];
this.prompt_responses = [];
this.resetPage();
}
@@ -18,18 +19,18 @@
Browser.prototype.resetPage = function() {
var ref;
ref = [0, []], this._counter = ref[0], this.pages = ref[1];
if (this.page != null) {
if (!this.page.closed) {
- if (this.page.currentUrl() !== 'about:blank') {
+ if (this.page.frameUrl() !== 'about:blank') {
this.page.clearLocalStorage();
}
this.page.close();
}
phantom.clearCookies();
}
- this.page = this.currentPage = new Poltergeist.WebPage;
+ this.page = this.currentPage = new Poltergeist.WebPage(null, this._page_settings);
this.page.setViewportSize({
width: this.width,
height: this.height
});
this.page.handle = "" + (this._counter++);
@@ -69,15 +70,17 @@
};
})(this);
page.onPageCreated = (function(_this) {
return function(newPage) {
var _page;
- _page = new Poltergeist.WebPage(newPage);
+ _page = new Poltergeist.WebPage(newPage, _this._page_settings);
_page.handle = "" + (_this._counter++);
_page.urlBlacklist = page.urlBlacklist;
_page.urlWhitelist = page.urlWhitelist;
_page.setViewportSize(page.viewportSize());
+ _page.setUserAgent(page.getUserAgent());
+ _page.setCustomHeaders(page.getPermanentCustomHeaders());
_this.setupPageHandlers(_page);
return _this.pages.push(_page);
};
})(this);
};
@@ -127,11 +130,11 @@
}
this.currentPage.state = 'loading';
this.processed_modal_messages = [];
this.confirm_processes = [];
this.prompt_responses = [];
- prevUrl = this.currentPage.source === null ? 'about:blank' : this.currentPage.currentUrl();
+ prevUrl = this.currentPage.source != null ? this.currentPage.currentUrl() : 'about:blank';
this.currentPage.open(url);
if (/#/.test(url) && prevUrl.split('#')[0] === url.split('#')[0]) {
this.currentPage.state = 'default';
return this.current_command.sendResponse({
status: 'success'
@@ -158,10 +161,14 @@
Browser.prototype.current_url = function() {
return this.current_command.sendResponse(this.currentPage.currentUrl());
};
+ Browser.prototype.frame_url = function() {
+ return this.current_command.sendResponse(this.currentPage.frameUrl());
+ };
+
Browser.prototype.status_code = function() {
return this.current_command.sendResponse(this.currentPage.statusCode);
};
Browser.prototype.body = function() {
@@ -174,10 +181,14 @@
Browser.prototype.title = function() {
return this.current_command.sendResponse(this.currentPage.title());
};
+ Browser.prototype.frame_title = function() {
+ return this.current_command.sendResponse(this.currentPage.frameTitle());
+ };
+
Browser.prototype.find = function(method, selector) {
return this.current_command.sendResponse({
page_id: this.currentPage.id,
ids: this.currentPage.find(method, selector)
});
@@ -309,12 +320,12 @@
}
(ref = this.currentPage).execute.apply(ref, ["function() { " + script + " }"].concat(slice.call(args)));
return this.current_command.sendResponse(true);
};
- Browser.prototype.frameUrl = function(frame_name) {
- return this.currentPage.frameUrl(frame_name);
+ Browser.prototype.frameUrlFor = function(frame_name) {
+ return this.currentPage.frameUrlFor(frame_name);
};
Browser.prototype.pushFrame = function(command, name, timeout) {
var frame, frame_url;
if (Array.isArray(name)) {
@@ -323,15 +334,15 @@
if (!name) {
frame.setAttribute('name', "_random_name_" + (new Date().getTime()));
name = frame.getAttribute('name');
}
}
- frame_url = this.frameUrl(name);
+ frame_url = this.frameUrlFor(name);
if (indexOf.call(this.currentPage.blockedUrls(), frame_url) >= 0) {
return command.sendResponse(true);
} else if (this.currentPage.pushFrame(name)) {
- if (frame_url && (frame_url !== 'about:blank') && (this.currentPage.currentUrl() === 'about:blank')) {
+ if (frame_url && (frame_url !== 'about:blank') && (this.currentPage.frameUrl() === 'about:blank')) {
this.currentPage.state = 'awaiting_frame_load';
return this.currentPage.waitState('default', function() {
return command.sendResponse(true);
});
} else {
@@ -419,15 +430,21 @@
} else {
return this.current_command.sendResponse(false);
}
};
- Browser.prototype.mouse_event = function(page_id, id, name) {
+ Browser.prototype.mouse_event = function(page_id, id, name, keys, offset) {
var command, event_page, last_mouse_event, node;
+ if (keys == null) {
+ keys = [];
+ }
+ if (offset == null) {
+ offset = {};
+ }
node = this.node(page_id, id);
this.currentPage.state = 'mouse_event';
- last_mouse_event = node.mouseEvent(name);
+ last_mouse_event = node.mouseEvent(name, keys, offset);
event_page = this.currentPage;
command = this.current_command;
return setTimeout(function() {
if (event_page.state === 'mouse_event') {
event_page.state = 'default';
@@ -442,20 +459,20 @@
});
}
}, 5);
};
- Browser.prototype.click = function(page_id, id) {
- return this.mouse_event(page_id, id, 'click');
+ Browser.prototype.click = function(page_id, id, keys, offset) {
+ return this.mouse_event(page_id, id, 'click', keys, offset);
};
- Browser.prototype.right_click = function(page_id, id) {
- return this.mouse_event(page_id, id, 'rightclick');
+ Browser.prototype.right_click = function(page_id, id, keys, offset) {
+ return this.mouse_event(page_id, id, 'rightclick', keys, offset);
};
- Browser.prototype.double_click = function(page_id, id) {
- return this.mouse_event(page_id, id, 'doubleclick');
+ Browser.prototype.double_click = function(page_id, id, keys, offset) {
+ return this.mouse_event(page_id, id, 'doubleclick', keys, offset);
};
Browser.prototype.hover = function(page_id, id) {
return this.mouse_event(page_id, id, 'mousemove');
};
@@ -641,25 +658,37 @@
Browser.prototype.get_headers = function() {
return this.current_command.sendResponse(this.currentPage.getCustomHeaders());
};
Browser.prototype.set_headers = function(headers) {
- if (headers['User-Agent']) {
- this.currentPage.setUserAgent(headers['User-Agent']);
- }
- this.currentPage.setCustomHeaders(headers);
- return this.current_command.sendResponse(true);
+ return this.add_headers(headers, false, false);
};
- Browser.prototype.add_headers = function(headers) {
- var allHeaders, name, value;
- allHeaders = this.currentPage.getCustomHeaders();
- for (name in headers) {
- value = headers[name];
- allHeaders[name] = value;
+ Browser.prototype.add_headers = function(headers, local, keepExisting) {
+ var pages;
+ if (local == null) {
+ local = false;
}
- return this.set_headers(allHeaders);
+ if (keepExisting == null) {
+ keepExisting = true;
+ }
+ pages = local ? [this.currentPage] : this.pages;
+ pages.forEach((function(_this) {
+ return function(page) {
+ var allHeaders, name, value;
+ allHeaders = keepExisting ? page.getCustomHeaders() : {};
+ for (name in headers) {
+ value = headers[name];
+ allHeaders[name] = value;
+ }
+ if (allHeaders['User-Agent']) {
+ page.setUserAgent(allHeaders['User-Agent']);
+ }
+ return page.setCustomHeaders(allHeaders);
+ };
+ })(this));
+ return this.current_command.sendResponse(true);
};
Browser.prototype.add_header = function(header, arg1) {
var permanent, ref;
permanent = (ref = arg1.permanent) != null ? ref : true;
@@ -667,11 +696,11 @@
this.currentPage.addTempHeader(header);
if (permanent === "no_redirect") {
this.currentPage.addTempHeaderToRemoveOnRedirect(header);
}
}
- return this.add_headers(header);
+ return this.add_headers(header, permanent !== true);
};
Browser.prototype.response_headers = function() {
return this.current_command.sendResponse(this.currentPage.responseHeaders());
};
@@ -710,9 +739,15 @@
return this.current_command.sendResponse(true);
};
Browser.prototype.set_debug = function(value) {
this._debug = value;
+ return this.current_command.sendResponse(true);
+ };
+
+ Browser.prototype.set_page_settings = function(settings) {
+ this._page_settings = settings;
+ this.page.setSettings(this._page_settings);
return this.current_command.sendResponse(true);
};
Browser.prototype.exit = function() {
return phantom.exit();