poltergeist 1.7.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/capybara/poltergeist/browser.rb +19 -8
- data/lib/capybara/poltergeist/client/agent.coffee +37 -12
- data/lib/capybara/poltergeist/client/browser.coffee +107 -90
- data/lib/capybara/poltergeist/client/cmd.coffee +17 -0
- data/lib/capybara/poltergeist/client/compiled/agent.js +97 -71
- data/lib/capybara/poltergeist/client/compiled/browser.js +204 -173
- data/lib/capybara/poltergeist/client/compiled/cmd.js +31 -0
- data/lib/capybara/poltergeist/client/compiled/connection.js +2 -2
- data/lib/capybara/poltergeist/client/compiled/main.js +45 -43
- data/lib/capybara/poltergeist/client/compiled/node.js +10 -11
- data/lib/capybara/poltergeist/client/compiled/web_page.js +89 -60
- data/lib/capybara/poltergeist/client/main.coffee +12 -9
- data/lib/capybara/poltergeist/client/node.coffee +6 -3
- data/lib/capybara/poltergeist/client/web_page.coffee +22 -8
- data/lib/capybara/poltergeist/command.rb +17 -0
- data/lib/capybara/poltergeist/driver.rb +40 -4
- data/lib/capybara/poltergeist/errors.rb +5 -1
- data/lib/capybara/poltergeist/inspector.rb +5 -5
- data/lib/capybara/poltergeist/node.rb +16 -1
- data/lib/capybara/poltergeist/server.rb +2 -2
- data/lib/capybara/poltergeist/version.rb +1 -1
- data/lib/capybara/poltergeist/web_socket_server.rb +23 -12
- metadata +11 -8
@@ -0,0 +1,31 @@
|
|
1
|
+
Poltergeist.Cmd = (function() {
|
2
|
+
function Cmd(owner, id, name, args) {
|
3
|
+
this.owner = owner;
|
4
|
+
this.id = id;
|
5
|
+
this.name = name;
|
6
|
+
this.args = args;
|
7
|
+
}
|
8
|
+
|
9
|
+
Cmd.prototype.sendResponse = function(response) {
|
10
|
+
var errors;
|
11
|
+
errors = this.browser.currentPage.errors;
|
12
|
+
this.browser.currentPage.clearErrors();
|
13
|
+
if (errors.length > 0 && this.browser.js_errors) {
|
14
|
+
return this.sendError(new Poltergeist.JavascriptError(errors));
|
15
|
+
} else {
|
16
|
+
return this.owner.sendResponse(this.id, response);
|
17
|
+
}
|
18
|
+
};
|
19
|
+
|
20
|
+
Cmd.prototype.sendError = function(errors) {
|
21
|
+
return this.owner.sendError(this.id, errors);
|
22
|
+
};
|
23
|
+
|
24
|
+
Cmd.prototype.run = function(browser) {
|
25
|
+
this.browser = browser;
|
26
|
+
return this.browser.runCommand(this);
|
27
|
+
};
|
28
|
+
|
29
|
+
return Cmd;
|
30
|
+
|
31
|
+
})();
|
@@ -1,10 +1,10 @@
|
|
1
|
-
var
|
1
|
+
var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
2
2
|
|
3
3
|
Poltergeist.Connection = (function() {
|
4
4
|
function Connection(owner, port) {
|
5
5
|
this.owner = owner;
|
6
6
|
this.port = port;
|
7
|
-
this.commandReceived =
|
7
|
+
this.commandReceived = bind(this.commandReceived, this);
|
8
8
|
this.socket = new WebSocket("ws://127.0.0.1:" + this.port + "/");
|
9
9
|
this.socket.onmessage = this.commandReceived;
|
10
10
|
this.socket.onclose = function() {
|
@@ -1,11 +1,11 @@
|
|
1
|
-
var Poltergeist, system,
|
2
|
-
|
3
|
-
|
1
|
+
var Poltergeist, system,
|
2
|
+
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
3
|
+
hasProp = {}.hasOwnProperty;
|
4
4
|
|
5
5
|
Poltergeist = (function() {
|
6
6
|
function Poltergeist(port, width, height) {
|
7
7
|
var that;
|
8
|
-
this.browser = new Poltergeist.Browser(
|
8
|
+
this.browser = new Poltergeist.Browser(width, height);
|
9
9
|
this.connection = new Poltergeist.Connection(this, port);
|
10
10
|
that = this;
|
11
11
|
phantom.onError = function(message, stack) {
|
@@ -15,28 +15,31 @@ Poltergeist = (function() {
|
|
15
15
|
}
|
16
16
|
|
17
17
|
Poltergeist.prototype.runCommand = function(command) {
|
18
|
-
var error;
|
18
|
+
var error, error1;
|
19
19
|
this.running = true;
|
20
|
+
command = new Poltergeist.Cmd(this, command.id, command.name, command.args);
|
20
21
|
try {
|
21
|
-
return this.browser
|
22
|
-
} catch (
|
23
|
-
error =
|
22
|
+
return command.run(this.browser);
|
23
|
+
} catch (error1) {
|
24
|
+
error = error1;
|
24
25
|
if (error instanceof Poltergeist.Error) {
|
25
|
-
return this.sendError(error);
|
26
|
+
return this.sendError(command.id, error);
|
26
27
|
} else {
|
27
|
-
return this.sendError(new Poltergeist.BrowserError(error.toString(), error.stack));
|
28
|
+
return this.sendError(command.id, new Poltergeist.BrowserError(error.toString(), error.stack));
|
28
29
|
}
|
29
30
|
}
|
30
31
|
};
|
31
32
|
|
32
|
-
Poltergeist.prototype.sendResponse = function(response) {
|
33
|
+
Poltergeist.prototype.sendResponse = function(command_id, response) {
|
33
34
|
return this.send({
|
35
|
+
command_id: command_id,
|
34
36
|
response: response
|
35
37
|
});
|
36
38
|
};
|
37
39
|
|
38
|
-
Poltergeist.prototype.sendError = function(error) {
|
40
|
+
Poltergeist.prototype.sendError = function(command_id, error) {
|
39
41
|
return this.send({
|
42
|
+
command_id: command_id,
|
40
43
|
error: {
|
41
44
|
name: error.name || 'Generic',
|
42
45
|
args: error.args && error.args() || [error.toString()]
|
@@ -64,12 +67,11 @@ Poltergeist.Error = (function() {
|
|
64
67
|
|
65
68
|
})();
|
66
69
|
|
67
|
-
Poltergeist.ObsoleteNode = (function(
|
68
|
-
|
70
|
+
Poltergeist.ObsoleteNode = (function(superClass) {
|
71
|
+
extend(ObsoleteNode, superClass);
|
69
72
|
|
70
73
|
function ObsoleteNode() {
|
71
|
-
|
72
|
-
return _ref;
|
74
|
+
return ObsoleteNode.__super__.constructor.apply(this, arguments);
|
73
75
|
}
|
74
76
|
|
75
77
|
ObsoleteNode.prototype.name = "Poltergeist.ObsoleteNode";
|
@@ -86,8 +88,8 @@ Poltergeist.ObsoleteNode = (function(_super) {
|
|
86
88
|
|
87
89
|
})(Poltergeist.Error);
|
88
90
|
|
89
|
-
Poltergeist.InvalidSelector = (function(
|
90
|
-
|
91
|
+
Poltergeist.InvalidSelector = (function(superClass) {
|
92
|
+
extend(InvalidSelector, superClass);
|
91
93
|
|
92
94
|
function InvalidSelector(method, selector) {
|
93
95
|
this.method = method;
|
@@ -104,8 +106,8 @@ Poltergeist.InvalidSelector = (function(_super) {
|
|
104
106
|
|
105
107
|
})(Poltergeist.Error);
|
106
108
|
|
107
|
-
Poltergeist.FrameNotFound = (function(
|
108
|
-
|
109
|
+
Poltergeist.FrameNotFound = (function(superClass) {
|
110
|
+
extend(FrameNotFound, superClass);
|
109
111
|
|
110
112
|
function FrameNotFound(frameName) {
|
111
113
|
this.frameName = frameName;
|
@@ -121,8 +123,8 @@ Poltergeist.FrameNotFound = (function(_super) {
|
|
121
123
|
|
122
124
|
})(Poltergeist.Error);
|
123
125
|
|
124
|
-
Poltergeist.MouseEventFailed = (function(
|
125
|
-
|
126
|
+
Poltergeist.MouseEventFailed = (function(superClass) {
|
127
|
+
extend(MouseEventFailed, superClass);
|
126
128
|
|
127
129
|
function MouseEventFailed(eventName, selector, position) {
|
128
130
|
this.eventName = eventName;
|
@@ -140,8 +142,8 @@ Poltergeist.MouseEventFailed = (function(_super) {
|
|
140
142
|
|
141
143
|
})(Poltergeist.Error);
|
142
144
|
|
143
|
-
Poltergeist.JavascriptError = (function(
|
144
|
-
|
145
|
+
Poltergeist.JavascriptError = (function(superClass) {
|
146
|
+
extend(JavascriptError, superClass);
|
145
147
|
|
146
148
|
function JavascriptError(errors) {
|
147
149
|
this.errors = errors;
|
@@ -157,12 +159,12 @@ Poltergeist.JavascriptError = (function(_super) {
|
|
157
159
|
|
158
160
|
})(Poltergeist.Error);
|
159
161
|
|
160
|
-
Poltergeist.BrowserError = (function(
|
161
|
-
|
162
|
+
Poltergeist.BrowserError = (function(superClass) {
|
163
|
+
extend(BrowserError, superClass);
|
162
164
|
|
163
|
-
function BrowserError(
|
164
|
-
this.message =
|
165
|
-
this.stack =
|
165
|
+
function BrowserError(message1, stack1) {
|
166
|
+
this.message = message1;
|
167
|
+
this.stack = stack1;
|
166
168
|
}
|
167
169
|
|
168
170
|
BrowserError.prototype.name = "Poltergeist.BrowserError";
|
@@ -175,30 +177,28 @@ Poltergeist.BrowserError = (function(_super) {
|
|
175
177
|
|
176
178
|
})(Poltergeist.Error);
|
177
179
|
|
178
|
-
Poltergeist.StatusFailError = (function(
|
179
|
-
|
180
|
+
Poltergeist.StatusFailError = (function(superClass) {
|
181
|
+
extend(StatusFailError, superClass);
|
180
182
|
|
181
|
-
function StatusFailError() {
|
182
|
-
|
183
|
-
return _ref1;
|
183
|
+
function StatusFailError(url) {
|
184
|
+
this.url = url;
|
184
185
|
}
|
185
186
|
|
186
187
|
StatusFailError.prototype.name = "Poltergeist.StatusFailError";
|
187
188
|
|
188
189
|
StatusFailError.prototype.args = function() {
|
189
|
-
return [];
|
190
|
+
return [this.url];
|
190
191
|
};
|
191
192
|
|
192
193
|
return StatusFailError;
|
193
194
|
|
194
195
|
})(Poltergeist.Error);
|
195
196
|
|
196
|
-
Poltergeist.NoSuchWindowError = (function(
|
197
|
-
|
197
|
+
Poltergeist.NoSuchWindowError = (function(superClass) {
|
198
|
+
extend(NoSuchWindowError, superClass);
|
198
199
|
|
199
200
|
function NoSuchWindowError() {
|
200
|
-
|
201
|
-
return _ref2;
|
201
|
+
return NoSuchWindowError.__super__.constructor.apply(this, arguments);
|
202
202
|
}
|
203
203
|
|
204
204
|
NoSuchWindowError.prototype.name = "Poltergeist.NoSuchWindowError";
|
@@ -211,13 +211,15 @@ Poltergeist.NoSuchWindowError = (function(_super) {
|
|
211
211
|
|
212
212
|
})(Poltergeist.Error);
|
213
213
|
|
214
|
-
phantom.injectJs(
|
214
|
+
phantom.injectJs(phantom.libraryPath + "/web_page.js");
|
215
|
+
|
216
|
+
phantom.injectJs(phantom.libraryPath + "/node.js");
|
215
217
|
|
216
|
-
phantom.injectJs(
|
218
|
+
phantom.injectJs(phantom.libraryPath + "/connection.js");
|
217
219
|
|
218
|
-
phantom.injectJs(
|
220
|
+
phantom.injectJs(phantom.libraryPath + "/cmd.js");
|
219
221
|
|
220
|
-
phantom.injectJs(
|
222
|
+
phantom.injectJs(phantom.libraryPath + "/browser.js");
|
221
223
|
|
222
224
|
system = require('system');
|
223
225
|
|
@@ -1,10 +1,9 @@
|
|
1
|
-
var
|
1
|
+
var slice = [].slice;
|
2
2
|
|
3
3
|
Poltergeist.Node = (function() {
|
4
|
-
var
|
5
|
-
_this = this;
|
4
|
+
var fn, i, len, name, ref;
|
6
5
|
|
7
|
-
Node.DELEGATES = ['allText', 'visibleText', 'getAttribute', 'value', 'set', 'setAttribute', 'isObsolete', 'removeAttribute', 'isMultiple', 'select', 'tagName', 'find', 'getAttributes', 'isVisible', 'position', 'trigger', 'parentId', 'parentIds', 'mouseEventTest', 'scrollIntoView', 'isDOMEqual', 'isDisabled', 'deleteText', 'containsSelection', 'path'];
|
6
|
+
Node.DELEGATES = ['allText', 'visibleText', 'getAttribute', 'value', 'set', 'setAttribute', 'isObsolete', 'removeAttribute', 'isMultiple', 'select', 'tagName', 'find', 'getAttributes', 'isVisible', 'isInViewport', 'position', 'trigger', 'parentId', 'parentIds', 'mouseEventTest', 'scrollIntoView', 'isDOMEqual', 'isDisabled', 'deleteText', 'containsSelection', 'path', 'getProperty'];
|
8
7
|
|
9
8
|
function Node(page, id) {
|
10
9
|
this.page = page;
|
@@ -15,17 +14,17 @@ Poltergeist.Node = (function() {
|
|
15
14
|
return new Poltergeist.Node(this.page, this.parentId());
|
16
15
|
};
|
17
16
|
|
18
|
-
|
19
|
-
|
17
|
+
ref = Node.DELEGATES;
|
18
|
+
fn = function(name) {
|
20
19
|
return Node.prototype[name] = function() {
|
21
20
|
var args;
|
22
|
-
args = 1 <= arguments.length ?
|
21
|
+
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
|
23
22
|
return this.page.nodeCall(this.id, name, args);
|
24
23
|
};
|
25
24
|
};
|
26
|
-
for (
|
27
|
-
name =
|
28
|
-
|
25
|
+
for (i = 0, len = ref.length; i < len; i++) {
|
26
|
+
name = ref[i];
|
27
|
+
fn(name);
|
29
28
|
}
|
30
29
|
|
31
30
|
Node.prototype.mouseEventPosition = function() {
|
@@ -86,4 +85,4 @@ Poltergeist.Node = (function() {
|
|
86
85
|
|
87
86
|
return Node;
|
88
87
|
|
89
|
-
})
|
88
|
+
})();
|
@@ -1,9 +1,8 @@
|
|
1
|
-
var
|
2
|
-
|
1
|
+
var slice = [].slice,
|
2
|
+
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
3
3
|
|
4
4
|
Poltergeist.WebPage = (function() {
|
5
|
-
var command, delegate,
|
6
|
-
_this = this;
|
5
|
+
var command, delegate, fn1, fn2, i, j, len, len1, ref, ref1;
|
7
6
|
|
8
7
|
WebPage.CALLBACKS = ['onConsoleMessage', 'onLoadFinished', 'onInitialized', 'onLoadStarted', 'onResourceRequested', 'onResourceReceived', 'onError', 'onNavigationRequested', 'onUrlChanged', 'onPageCreated', 'onClosing'];
|
9
8
|
|
@@ -14,7 +13,7 @@ Poltergeist.WebPage = (function() {
|
|
14
13
|
WebPage.EXTENSIONS = [];
|
15
14
|
|
16
15
|
function WebPage(_native) {
|
17
|
-
var callback,
|
16
|
+
var callback, i, len, ref;
|
18
17
|
this._native = _native;
|
19
18
|
this._native || (this._native = require('webpage').create());
|
20
19
|
this.id = 0;
|
@@ -27,35 +26,35 @@ Poltergeist.WebPage = (function() {
|
|
27
26
|
this._networkTraffic = {};
|
28
27
|
this._tempHeaders = {};
|
29
28
|
this._blockedUrls = [];
|
30
|
-
|
31
|
-
for (
|
32
|
-
callback =
|
29
|
+
ref = WebPage.CALLBACKS;
|
30
|
+
for (i = 0, len = ref.length; i < len; i++) {
|
31
|
+
callback = ref[i];
|
33
32
|
this.bindCallback(callback);
|
34
33
|
}
|
35
34
|
}
|
36
35
|
|
37
|
-
|
38
|
-
|
36
|
+
ref = WebPage.COMMANDS;
|
37
|
+
fn1 = function(command) {
|
39
38
|
return WebPage.prototype[command] = function() {
|
40
39
|
var args;
|
41
|
-
args = 1 <= arguments.length ?
|
40
|
+
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
|
42
41
|
return this.runCommand(command, args);
|
43
42
|
};
|
44
43
|
};
|
45
|
-
for (
|
46
|
-
command =
|
47
|
-
|
44
|
+
for (i = 0, len = ref.length; i < len; i++) {
|
45
|
+
command = ref[i];
|
46
|
+
fn1(command);
|
48
47
|
}
|
49
48
|
|
50
|
-
|
51
|
-
|
49
|
+
ref1 = WebPage.DELEGATES;
|
50
|
+
fn2 = function(delegate) {
|
52
51
|
return WebPage.prototype[delegate] = function() {
|
53
52
|
return this._native[delegate].apply(this._native, arguments);
|
54
53
|
};
|
55
54
|
};
|
56
|
-
for (
|
57
|
-
delegate =
|
58
|
-
|
55
|
+
for (j = 0, len1 = ref1.length; j < len1; j++) {
|
56
|
+
delegate = ref1[j];
|
57
|
+
fn2(delegate);
|
59
58
|
}
|
60
59
|
|
61
60
|
WebPage.prototype.onInitializedNative = function() {
|
@@ -111,18 +110,18 @@ Poltergeist.WebPage = (function() {
|
|
111
110
|
};
|
112
111
|
|
113
112
|
WebPage.prototype.onResourceRequestedNative = function(request, net) {
|
114
|
-
var abort,
|
113
|
+
var abort, ref2;
|
115
114
|
abort = this.urlBlacklist.some(function(blacklisted_url) {
|
116
115
|
return request.url.indexOf(blacklisted_url) !== -1;
|
117
116
|
});
|
118
117
|
if (abort) {
|
119
|
-
if (
|
118
|
+
if (ref2 = request.url, indexOf.call(this._blockedUrls, ref2) < 0) {
|
120
119
|
this._blockedUrls.push(request.url);
|
121
120
|
}
|
122
121
|
return net.abort();
|
123
122
|
} else {
|
124
123
|
this.lastRequestId = request.id;
|
125
|
-
if (request.url === this.redirectURL) {
|
124
|
+
if (this.normalizeURL(request.url) === this.redirectURL) {
|
126
125
|
this.redirectURL = null;
|
127
126
|
this.requestId = request.id;
|
128
127
|
}
|
@@ -134,13 +133,13 @@ Poltergeist.WebPage = (function() {
|
|
134
133
|
};
|
135
134
|
|
136
135
|
WebPage.prototype.onResourceReceivedNative = function(response) {
|
137
|
-
var
|
138
|
-
if ((
|
139
|
-
|
136
|
+
var ref2;
|
137
|
+
if ((ref2 = this._networkTraffic[response.id]) != null) {
|
138
|
+
ref2.responseParts.push(response);
|
140
139
|
}
|
141
140
|
if (this.requestId === response.id) {
|
142
141
|
if (response.redirectURL) {
|
143
|
-
return this.redirectURL = response.redirectURL;
|
142
|
+
return this.redirectURL = this.normalizeURL(response.redirectURL);
|
144
143
|
} else {
|
145
144
|
this.statusCode = response.status;
|
146
145
|
return this._responseHeaders = response.headers;
|
@@ -149,18 +148,18 @@ Poltergeist.WebPage = (function() {
|
|
149
148
|
};
|
150
149
|
|
151
150
|
WebPage.prototype.injectAgent = function() {
|
152
|
-
var extension,
|
151
|
+
var extension, k, len2, ref2, results;
|
153
152
|
if (this["native"]().evaluate(function() {
|
154
153
|
return typeof __poltergeist;
|
155
154
|
}) === "undefined") {
|
156
|
-
this["native"]().injectJs(
|
157
|
-
|
158
|
-
|
159
|
-
for (
|
160
|
-
extension =
|
161
|
-
|
155
|
+
this["native"]().injectJs(phantom.libraryPath + "/agent.js");
|
156
|
+
ref2 = WebPage.EXTENSIONS;
|
157
|
+
results = [];
|
158
|
+
for (k = 0, len2 = ref2.length; k < len2; k++) {
|
159
|
+
extension = ref2[k];
|
160
|
+
results.push(this["native"]().injectJs(extension));
|
162
161
|
}
|
163
|
-
return
|
162
|
+
return results;
|
164
163
|
}
|
165
164
|
};
|
166
165
|
|
@@ -195,20 +194,22 @@ Poltergeist.WebPage = (function() {
|
|
195
194
|
};
|
196
195
|
|
197
196
|
WebPage.prototype.keyModifierKeys = function(names) {
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
197
|
+
return names.split(',').map((function(_this) {
|
198
|
+
return function(name) {
|
199
|
+
return _this.keyCode(name.charAt(0).toUpperCase() + name.substring(1));
|
200
|
+
};
|
201
|
+
})(this));
|
202
202
|
};
|
203
203
|
|
204
204
|
WebPage.prototype.waitState = function(state, callback) {
|
205
|
-
var _this = this;
|
206
205
|
if (this.state === state) {
|
207
206
|
return callback.call();
|
208
207
|
} else {
|
209
|
-
return setTimeout((function() {
|
210
|
-
return
|
211
|
-
|
208
|
+
return setTimeout(((function(_this) {
|
209
|
+
return function() {
|
210
|
+
return _this.waitState(state, callback);
|
211
|
+
};
|
212
|
+
})(this)), 100);
|
212
213
|
}
|
213
214
|
};
|
214
215
|
|
@@ -241,13 +242,13 @@ Poltergeist.WebPage = (function() {
|
|
241
242
|
return this["native"]().frameTitle;
|
242
243
|
};
|
243
244
|
|
244
|
-
WebPage.prototype.frameUrl = function(
|
245
|
+
WebPage.prototype.frameUrl = function(frameNameOrId) {
|
245
246
|
var query;
|
246
|
-
query = function(
|
247
|
-
var
|
248
|
-
return (
|
247
|
+
query = function(frameNameOrId) {
|
248
|
+
var ref2;
|
249
|
+
return (ref2 = document.querySelector("iframe[name='" + frameNameOrId + "'], iframe[id='" + frameNameOrId + "']")) != null ? ref2.src : void 0;
|
249
250
|
};
|
250
|
-
return this.evaluate(query,
|
251
|
+
return this.evaluate(query, frameNameOrId);
|
251
252
|
};
|
252
253
|
|
253
254
|
WebPage.prototype.clearErrors = function() {
|
@@ -322,32 +323,53 @@ Poltergeist.WebPage = (function() {
|
|
322
323
|
};
|
323
324
|
|
324
325
|
WebPage.prototype.addTempHeader = function(header) {
|
325
|
-
var name,
|
326
|
-
|
326
|
+
var name, results, value;
|
327
|
+
results = [];
|
327
328
|
for (name in header) {
|
328
329
|
value = header[name];
|
329
|
-
|
330
|
+
results.push(this._tempHeaders[name] = value);
|
330
331
|
}
|
331
|
-
return
|
332
|
+
return results;
|
332
333
|
};
|
333
334
|
|
334
335
|
WebPage.prototype.removeTempHeaders = function() {
|
335
|
-
var allHeaders, name,
|
336
|
+
var allHeaders, name, ref2, value;
|
336
337
|
allHeaders = this.getCustomHeaders();
|
337
|
-
|
338
|
-
for (name in
|
339
|
-
value =
|
338
|
+
ref2 = this._tempHeaders;
|
339
|
+
for (name in ref2) {
|
340
|
+
value = ref2[name];
|
340
341
|
delete allHeaders[name];
|
341
342
|
}
|
342
343
|
return this.setCustomHeaders(allHeaders);
|
343
344
|
};
|
344
345
|
|
345
346
|
WebPage.prototype.pushFrame = function(name) {
|
347
|
+
var frame_no;
|
346
348
|
if (this["native"]().switchToFrame(name)) {
|
347
349
|
this.frames.push(name);
|
348
350
|
return true;
|
349
351
|
} else {
|
350
|
-
|
352
|
+
frame_no = this["native"]().evaluate(function(frame_name) {
|
353
|
+
var f, frames, idx;
|
354
|
+
frames = document.querySelectorAll("iframe, frame");
|
355
|
+
return ((function() {
|
356
|
+
var k, len2, results;
|
357
|
+
results = [];
|
358
|
+
for (idx = k = 0, len2 = frames.length; k < len2; idx = ++k) {
|
359
|
+
f = frames[idx];
|
360
|
+
if ((f != null ? f['name'] : void 0) === frame_name || (f != null ? f['id'] : void 0) === frame_name) {
|
361
|
+
results.push(idx);
|
362
|
+
}
|
363
|
+
}
|
364
|
+
return results;
|
365
|
+
})())[0];
|
366
|
+
}, name);
|
367
|
+
if ((frame_no != null) && this["native"]().switchToFrame(frame_no)) {
|
368
|
+
this.frames.push(name);
|
369
|
+
return true;
|
370
|
+
} else {
|
371
|
+
return false;
|
372
|
+
}
|
351
373
|
}
|
352
374
|
};
|
353
375
|
|
@@ -403,7 +425,7 @@ Poltergeist.WebPage = (function() {
|
|
403
425
|
|
404
426
|
WebPage.prototype.evaluate = function() {
|
405
427
|
var args, fn;
|
406
|
-
fn = arguments[0], args = 2 <= arguments.length ?
|
428
|
+
fn = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
|
407
429
|
this.injectAgent();
|
408
430
|
return JSON.parse(this.sanitize(this["native"]().evaluate("function() { return PoltergeistAgent.stringify(" + (this.stringifyCall(fn, args)) + ") }")));
|
409
431
|
};
|
@@ -418,7 +440,7 @@ Poltergeist.WebPage = (function() {
|
|
418
440
|
|
419
441
|
WebPage.prototype.execute = function() {
|
420
442
|
var args, fn;
|
421
|
-
fn = arguments[0], args = 2 <= arguments.length ?
|
443
|
+
fn = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
|
422
444
|
return this["native"]().evaluate("function() { " + (this.stringifyCall(fn, args)) + " }");
|
423
445
|
};
|
424
446
|
|
@@ -426,7 +448,7 @@ Poltergeist.WebPage = (function() {
|
|
426
448
|
if (args.length === 0) {
|
427
449
|
return "(" + (fn.toString()) + ")()";
|
428
450
|
} else {
|
429
|
-
return "(" + (fn.toString()) + ").apply(this, JSON.parse(" + (JSON.stringify(JSON.stringify(args))) + "))";
|
451
|
+
return "(" + (fn.toString()) + ").apply(this, PoltergeistAgent.JSON.parse(" + (JSON.stringify(JSON.stringify(args))) + "))";
|
430
452
|
}
|
431
453
|
};
|
432
454
|
|
@@ -476,6 +498,13 @@ Poltergeist.WebPage = (function() {
|
|
476
498
|
return this["native"]().canGoForward;
|
477
499
|
};
|
478
500
|
|
501
|
+
WebPage.prototype.normalizeURL = function(url) {
|
502
|
+
var parser;
|
503
|
+
parser = document.createElement('a');
|
504
|
+
parser.href = url;
|
505
|
+
return parser.href;
|
506
|
+
};
|
507
|
+
|
479
508
|
return WebPage;
|
480
509
|
|
481
|
-
})
|
510
|
+
})();
|