undead 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/undead.rb +1 -2
- data/lib/undead/agent.rb +6 -11
- data/lib/undead/browser.rb +68 -0
- data/lib/undead/client.rb +151 -0
- data/lib/undead/client/compiled/agent.js +594 -0
- data/lib/undead/client/compiled/browser.js +692 -0
- data/lib/undead/client/compiled/cmd.js +31 -0
- data/lib/undead/client/compiled/connection.js +25 -0
- data/lib/undead/client/compiled/main.js +229 -0
- data/lib/undead/client/compiled/node.js +187 -0
- data/lib/undead/client/compiled/web_page.js +589 -0
- data/lib/undead/command.rb +20 -0
- data/lib/undead/driver.rb +73 -0
- data/lib/undead/errors.rb +187 -0
- data/lib/undead/server.rb +44 -0
- data/lib/undead/utility.rb +7 -0
- data/lib/undead/version.rb +1 -1
- data/lib/undead/web_socket_server.rb +109 -0
- data/undead.gemspec +4 -4
- metadata +27 -11
@@ -0,0 +1,692 @@
|
|
1
|
+
var 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; };
|
2
|
+
|
3
|
+
Poltergeist.Browser = (function() {
|
4
|
+
function Browser(width, height) {
|
5
|
+
this.width = width || 1024;
|
6
|
+
this.height = height || 768;
|
7
|
+
this.pages = [];
|
8
|
+
this.js_errors = true;
|
9
|
+
this._debug = false;
|
10
|
+
this._counter = 0;
|
11
|
+
this.processed_modal_messages = [];
|
12
|
+
this.confirm_processes = [];
|
13
|
+
this.prompt_responses = [];
|
14
|
+
this.resetPage();
|
15
|
+
}
|
16
|
+
|
17
|
+
Browser.prototype.resetPage = function() {
|
18
|
+
var ref;
|
19
|
+
ref = [0, []], this._counter = ref[0], this.pages = ref[1];
|
20
|
+
if (this.page != null) {
|
21
|
+
if (!this.page.closed) {
|
22
|
+
if (this.page.currentUrl() !== 'about:blank') {
|
23
|
+
this.page.clearLocalStorage();
|
24
|
+
}
|
25
|
+
this.page.release();
|
26
|
+
}
|
27
|
+
phantom.clearCookies();
|
28
|
+
}
|
29
|
+
this.page = this.currentPage = new Poltergeist.WebPage;
|
30
|
+
this.page.setViewportSize({
|
31
|
+
width: this.width,
|
32
|
+
height: this.height
|
33
|
+
});
|
34
|
+
this.page.handle = "" + (this._counter++);
|
35
|
+
this.pages.push(this.page);
|
36
|
+
this.processed_modal_messages = [];
|
37
|
+
this.confirm_processes = [];
|
38
|
+
this.prompt_responses = [];
|
39
|
+
this.page["native"]().onAlert = (function(_this) {
|
40
|
+
return function(msg) {
|
41
|
+
_this.setModalMessage(msg);
|
42
|
+
};
|
43
|
+
})(this);
|
44
|
+
this.page["native"]().onConfirm = (function(_this) {
|
45
|
+
return function(msg) {
|
46
|
+
var process;
|
47
|
+
process = _this.confirm_processes.pop();
|
48
|
+
if (process === void 0) {
|
49
|
+
process = true;
|
50
|
+
}
|
51
|
+
_this.setModalMessage(msg);
|
52
|
+
return process;
|
53
|
+
};
|
54
|
+
})(this);
|
55
|
+
this.page["native"]().onPrompt = (function(_this) {
|
56
|
+
return function(msg, defaultVal) {
|
57
|
+
var response;
|
58
|
+
response = _this.prompt_responses.pop();
|
59
|
+
if (response === void 0 || response === false) {
|
60
|
+
response = defaultVal;
|
61
|
+
}
|
62
|
+
_this.setModalMessage(msg);
|
63
|
+
return response;
|
64
|
+
};
|
65
|
+
})(this);
|
66
|
+
this.page.onPageCreated = (function(_this) {
|
67
|
+
return function(newPage) {
|
68
|
+
var page;
|
69
|
+
page = new Poltergeist.WebPage(newPage);
|
70
|
+
page.handle = "" + (_this._counter++);
|
71
|
+
return _this.pages.push(page);
|
72
|
+
};
|
73
|
+
})(this);
|
74
|
+
};
|
75
|
+
|
76
|
+
Browser.prototype.getPageByHandle = function(handle) {
|
77
|
+
return this.pages.filter(function(p) {
|
78
|
+
return !p.closed && p.handle === handle;
|
79
|
+
})[0];
|
80
|
+
};
|
81
|
+
|
82
|
+
Browser.prototype.runCommand = function(command) {
|
83
|
+
this.current_command = command;
|
84
|
+
this.currentPage.state = 'default';
|
85
|
+
return this[command.name].apply(this, command.args);
|
86
|
+
};
|
87
|
+
|
88
|
+
Browser.prototype.debug = function(message) {
|
89
|
+
if (this._debug) {
|
90
|
+
return console.log("poltergeist [" + (new Date().getTime()) + "] " + message);
|
91
|
+
}
|
92
|
+
};
|
93
|
+
|
94
|
+
Browser.prototype.setModalMessage = function(msg) {
|
95
|
+
this.processed_modal_messages.push(msg);
|
96
|
+
};
|
97
|
+
|
98
|
+
Browser.prototype.add_extension = function(extension) {
|
99
|
+
this.currentPage.injectExtension(extension);
|
100
|
+
return this.current_command.sendResponse('success');
|
101
|
+
};
|
102
|
+
|
103
|
+
Browser.prototype.node = function(page_id, id) {
|
104
|
+
if (this.currentPage.id === page_id) {
|
105
|
+
return this.currentPage.get(id);
|
106
|
+
} else {
|
107
|
+
throw new Poltergeist.ObsoleteNode;
|
108
|
+
}
|
109
|
+
};
|
110
|
+
|
111
|
+
Browser.prototype.visit = function(url, max_wait) {
|
112
|
+
var command, prevUrl;
|
113
|
+
if (max_wait == null) {
|
114
|
+
max_wait = 0;
|
115
|
+
}
|
116
|
+
this.currentPage.state = 'loading';
|
117
|
+
this.processed_modal_messages = [];
|
118
|
+
this.confirm_processes = [];
|
119
|
+
this.prompt_responses = [];
|
120
|
+
prevUrl = this.currentPage.source === null ? 'about:blank' : this.currentPage.currentUrl();
|
121
|
+
this.currentPage.open(url);
|
122
|
+
if (/#/.test(url) && prevUrl.split('#')[0] === url.split('#')[0]) {
|
123
|
+
this.currentPage.state = 'default';
|
124
|
+
return this.current_command.sendResponse({
|
125
|
+
status: 'success'
|
126
|
+
});
|
127
|
+
} else {
|
128
|
+
command = this.current_command;
|
129
|
+
this.currentPage.waitState('default', (function(_this) {
|
130
|
+
return function() {
|
131
|
+
if (_this.currentPage.statusCode === null && _this.currentPage.status === 'fail') {
|
132
|
+
return command.sendError(new Poltergeist.StatusFailError(url));
|
133
|
+
} else {
|
134
|
+
return command.sendResponse({
|
135
|
+
status: _this.currentPage.status
|
136
|
+
});
|
137
|
+
}
|
138
|
+
};
|
139
|
+
})(this), max_wait, (function(_this) {
|
140
|
+
return function() {
|
141
|
+
var msg, resources;
|
142
|
+
resources = _this.currentPage.openResourceRequests();
|
143
|
+
msg = resources.length ? "Timed out with the following resources still waiting " + (_this.currentPage.openResourceRequests().join(',')) : void 0;
|
144
|
+
return command.sendError(new Poltergeist.StatusFailError(url, msg));
|
145
|
+
};
|
146
|
+
})(this));
|
147
|
+
}
|
148
|
+
};
|
149
|
+
|
150
|
+
Browser.prototype.current_url = function() {
|
151
|
+
return this.current_command.sendResponse(this.currentPage.currentUrl());
|
152
|
+
};
|
153
|
+
|
154
|
+
Browser.prototype.status_code = function() {
|
155
|
+
return this.current_command.sendResponse(this.currentPage.statusCode);
|
156
|
+
};
|
157
|
+
|
158
|
+
Browser.prototype.body = function() {
|
159
|
+
return this.current_command.sendResponse(this.currentPage.content());
|
160
|
+
};
|
161
|
+
|
162
|
+
Browser.prototype.source = function() {
|
163
|
+
return this.current_command.sendResponse(this.currentPage.source);
|
164
|
+
};
|
165
|
+
|
166
|
+
Browser.prototype.title = function() {
|
167
|
+
return this.current_command.sendResponse(this.currentPage.title());
|
168
|
+
};
|
169
|
+
|
170
|
+
Browser.prototype.find = function(method, selector) {
|
171
|
+
return this.current_command.sendResponse({
|
172
|
+
page_id: this.currentPage.id,
|
173
|
+
ids: this.currentPage.find(method, selector)
|
174
|
+
});
|
175
|
+
};
|
176
|
+
|
177
|
+
Browser.prototype.find_within = function(page_id, id, method, selector) {
|
178
|
+
return this.current_command.sendResponse(this.node(page_id, id).find(method, selector));
|
179
|
+
};
|
180
|
+
|
181
|
+
Browser.prototype.all_text = function(page_id, id) {
|
182
|
+
return this.current_command.sendResponse(this.node(page_id, id).allText());
|
183
|
+
};
|
184
|
+
|
185
|
+
Browser.prototype.visible_text = function(page_id, id) {
|
186
|
+
return this.current_command.sendResponse(this.node(page_id, id).visibleText());
|
187
|
+
};
|
188
|
+
|
189
|
+
Browser.prototype.delete_text = function(page_id, id) {
|
190
|
+
return this.current_command.sendResponse(this.node(page_id, id).deleteText());
|
191
|
+
};
|
192
|
+
|
193
|
+
Browser.prototype.property = function(page_id, id, name) {
|
194
|
+
return this.current_command.sendResponse(this.node(page_id, id).getProperty(name));
|
195
|
+
};
|
196
|
+
|
197
|
+
Browser.prototype.attribute = function(page_id, id, name) {
|
198
|
+
return this.current_command.sendResponse(this.node(page_id, id).getAttribute(name));
|
199
|
+
};
|
200
|
+
|
201
|
+
Browser.prototype.attributes = function(page_id, id, name) {
|
202
|
+
return this.current_command.sendResponse(this.node(page_id, id).getAttributes());
|
203
|
+
};
|
204
|
+
|
205
|
+
Browser.prototype.parents = function(page_id, id) {
|
206
|
+
return this.current_command.sendResponse(this.node(page_id, id).parentIds());
|
207
|
+
};
|
208
|
+
|
209
|
+
Browser.prototype.value = function(page_id, id) {
|
210
|
+
return this.current_command.sendResponse(this.node(page_id, id).value());
|
211
|
+
};
|
212
|
+
|
213
|
+
Browser.prototype.set = function(page_id, id, value) {
|
214
|
+
this.node(page_id, id).set(value);
|
215
|
+
return this.current_command.sendResponse(true);
|
216
|
+
};
|
217
|
+
|
218
|
+
Browser.prototype.select_file = function(page_id, id, value) {
|
219
|
+
var node;
|
220
|
+
node = this.node(page_id, id);
|
221
|
+
this.currentPage.beforeUpload(node.id);
|
222
|
+
this.currentPage.uploadFile('[_poltergeist_selected]', value);
|
223
|
+
this.currentPage.afterUpload(node.id);
|
224
|
+
if (phantom.version.major === 2 && phantom.version.minor === 0) {
|
225
|
+
return this.click(page_id, id);
|
226
|
+
} else {
|
227
|
+
return this.current_command.sendResponse(true);
|
228
|
+
}
|
229
|
+
};
|
230
|
+
|
231
|
+
Browser.prototype.select = function(page_id, id, value) {
|
232
|
+
return this.current_command.sendResponse(this.node(page_id, id).select(value));
|
233
|
+
};
|
234
|
+
|
235
|
+
Browser.prototype.tag_name = function(page_id, id) {
|
236
|
+
return this.current_command.sendResponse(this.node(page_id, id).tagName());
|
237
|
+
};
|
238
|
+
|
239
|
+
Browser.prototype.visible = function(page_id, id) {
|
240
|
+
return this.current_command.sendResponse(this.node(page_id, id).isVisible());
|
241
|
+
};
|
242
|
+
|
243
|
+
Browser.prototype.disabled = function(page_id, id) {
|
244
|
+
return this.current_command.sendResponse(this.node(page_id, id).isDisabled());
|
245
|
+
};
|
246
|
+
|
247
|
+
Browser.prototype.path = function(page_id, id) {
|
248
|
+
return this.current_command.sendResponse(this.node(page_id, id).path());
|
249
|
+
};
|
250
|
+
|
251
|
+
Browser.prototype.evaluate = function(script) {
|
252
|
+
return this.current_command.sendResponse(this.currentPage.evaluate("function() { return " + script + " }"));
|
253
|
+
};
|
254
|
+
|
255
|
+
Browser.prototype.execute = function(script) {
|
256
|
+
this.currentPage.execute("function() { " + script + " }");
|
257
|
+
return this.current_command.sendResponse(true);
|
258
|
+
};
|
259
|
+
|
260
|
+
Browser.prototype.frameUrl = function(frame_name) {
|
261
|
+
return this.currentPage.frameUrl(frame_name);
|
262
|
+
};
|
263
|
+
|
264
|
+
Browser.prototype.pushFrame = function(command, name, timeout) {
|
265
|
+
var frame, ref;
|
266
|
+
if (Array.isArray(name)) {
|
267
|
+
frame = this.node.apply(this, name);
|
268
|
+
name = frame.getAttribute('name') || frame.getAttribute('id');
|
269
|
+
if (!name) {
|
270
|
+
frame.setAttribute('name', "_random_name_" + (new Date().getTime()));
|
271
|
+
name = frame.getAttribute('name');
|
272
|
+
}
|
273
|
+
}
|
274
|
+
if (ref = this.frameUrl(name), indexOf.call(this.currentPage.blockedUrls(), ref) >= 0) {
|
275
|
+
return command.sendResponse(true);
|
276
|
+
} else if (this.currentPage.pushFrame(name)) {
|
277
|
+
if (this.currentPage.currentUrl() === 'about:blank') {
|
278
|
+
this.currentPage.state = 'awaiting_frame_load';
|
279
|
+
return this.currentPage.waitState('default', (function(_this) {
|
280
|
+
return function() {
|
281
|
+
return command.sendResponse(true);
|
282
|
+
};
|
283
|
+
})(this));
|
284
|
+
} else {
|
285
|
+
return command.sendResponse(true);
|
286
|
+
}
|
287
|
+
} else {
|
288
|
+
if (new Date().getTime() < timeout) {
|
289
|
+
return setTimeout(((function(_this) {
|
290
|
+
return function() {
|
291
|
+
return _this.pushFrame(command, name, timeout);
|
292
|
+
};
|
293
|
+
})(this)), 50);
|
294
|
+
} else {
|
295
|
+
return command.sendError(new Poltergeist.FrameNotFound(name));
|
296
|
+
}
|
297
|
+
}
|
298
|
+
};
|
299
|
+
|
300
|
+
Browser.prototype.push_frame = function(name, timeout) {
|
301
|
+
if (timeout == null) {
|
302
|
+
timeout = (new Date().getTime()) + 2000;
|
303
|
+
}
|
304
|
+
return this.pushFrame(this.current_command, name, timeout);
|
305
|
+
};
|
306
|
+
|
307
|
+
Browser.prototype.pop_frame = function() {
|
308
|
+
return this.current_command.sendResponse(this.currentPage.popFrame());
|
309
|
+
};
|
310
|
+
|
311
|
+
Browser.prototype.window_handles = function() {
|
312
|
+
var handles;
|
313
|
+
handles = this.pages.filter(function(p) {
|
314
|
+
return !p.closed;
|
315
|
+
}).map(function(p) {
|
316
|
+
return p.handle;
|
317
|
+
});
|
318
|
+
return this.current_command.sendResponse(handles);
|
319
|
+
};
|
320
|
+
|
321
|
+
Browser.prototype.window_handle = function(name) {
|
322
|
+
var handle, page;
|
323
|
+
if (name == null) {
|
324
|
+
name = null;
|
325
|
+
}
|
326
|
+
handle = name ? (page = this.pages.filter(function(p) {
|
327
|
+
return !p.closed && p.windowName() === name;
|
328
|
+
})[0], page ? page.handle : null) : this.currentPage.handle;
|
329
|
+
return this.current_command.sendResponse(handle);
|
330
|
+
};
|
331
|
+
|
332
|
+
Browser.prototype.switch_to_window = function(handle) {
|
333
|
+
var command, page;
|
334
|
+
command = this.current_command;
|
335
|
+
page = this.getPageByHandle(handle);
|
336
|
+
if (page) {
|
337
|
+
if (page !== this.currentPage) {
|
338
|
+
return page.waitState('default', (function(_this) {
|
339
|
+
return function() {
|
340
|
+
_this.currentPage = page;
|
341
|
+
return command.sendResponse(true);
|
342
|
+
};
|
343
|
+
})(this));
|
344
|
+
} else {
|
345
|
+
return command.sendResponse(true);
|
346
|
+
}
|
347
|
+
} else {
|
348
|
+
throw new Poltergeist.NoSuchWindowError;
|
349
|
+
}
|
350
|
+
};
|
351
|
+
|
352
|
+
Browser.prototype.open_new_window = function() {
|
353
|
+
this.execute('window.open()');
|
354
|
+
return this.current_command.sendResponse(true);
|
355
|
+
};
|
356
|
+
|
357
|
+
Browser.prototype.close_window = function(handle) {
|
358
|
+
var page;
|
359
|
+
page = this.getPageByHandle(handle);
|
360
|
+
if (page) {
|
361
|
+
page.release();
|
362
|
+
return this.current_command.sendResponse(true);
|
363
|
+
} else {
|
364
|
+
return this.current_command.sendResponse(false);
|
365
|
+
}
|
366
|
+
};
|
367
|
+
|
368
|
+
Browser.prototype.mouse_event = function(page_id, id, name) {
|
369
|
+
var command, node;
|
370
|
+
node = this.node(page_id, id);
|
371
|
+
this.currentPage.state = 'mouse_event';
|
372
|
+
this.last_mouse_event = node.mouseEvent(name);
|
373
|
+
command = this.current_command;
|
374
|
+
return setTimeout((function(_this) {
|
375
|
+
return function() {
|
376
|
+
if (_this.currentPage.state === 'mouse_event') {
|
377
|
+
_this.currentPage.state = 'default';
|
378
|
+
return command.sendResponse({
|
379
|
+
position: _this.last_mouse_event
|
380
|
+
});
|
381
|
+
} else {
|
382
|
+
return _this.currentPage.waitState('default', function() {
|
383
|
+
return command.sendResponse({
|
384
|
+
position: _this.last_mouse_event
|
385
|
+
});
|
386
|
+
});
|
387
|
+
}
|
388
|
+
};
|
389
|
+
})(this), 5);
|
390
|
+
};
|
391
|
+
|
392
|
+
Browser.prototype.click = function(page_id, id) {
|
393
|
+
return this.mouse_event(page_id, id, 'click');
|
394
|
+
};
|
395
|
+
|
396
|
+
Browser.prototype.right_click = function(page_id, id) {
|
397
|
+
return this.mouse_event(page_id, id, 'rightclick');
|
398
|
+
};
|
399
|
+
|
400
|
+
Browser.prototype.double_click = function(page_id, id) {
|
401
|
+
return this.mouse_event(page_id, id, 'doubleclick');
|
402
|
+
};
|
403
|
+
|
404
|
+
Browser.prototype.hover = function(page_id, id) {
|
405
|
+
return this.mouse_event(page_id, id, 'mousemove');
|
406
|
+
};
|
407
|
+
|
408
|
+
Browser.prototype.click_coordinates = function(x, y) {
|
409
|
+
this.currentPage.sendEvent('click', x, y);
|
410
|
+
return this.current_command.sendResponse({
|
411
|
+
click: {
|
412
|
+
x: x,
|
413
|
+
y: y
|
414
|
+
}
|
415
|
+
});
|
416
|
+
};
|
417
|
+
|
418
|
+
Browser.prototype.drag = function(page_id, id, other_id) {
|
419
|
+
this.node(page_id, id).dragTo(this.node(page_id, other_id));
|
420
|
+
return this.current_command.sendResponse(true);
|
421
|
+
};
|
422
|
+
|
423
|
+
Browser.prototype.drag_by = function(page_id, id, x, y) {
|
424
|
+
this.node(page_id, id).dragBy(x, y);
|
425
|
+
return this.current_command.sendResponse(true);
|
426
|
+
};
|
427
|
+
|
428
|
+
Browser.prototype.trigger = function(page_id, id, event) {
|
429
|
+
this.node(page_id, id).trigger(event);
|
430
|
+
return this.current_command.sendResponse(event);
|
431
|
+
};
|
432
|
+
|
433
|
+
Browser.prototype.equals = function(page_id, id, other_id) {
|
434
|
+
return this.current_command.sendResponse(this.node(page_id, id).isEqual(this.node(page_id, other_id)));
|
435
|
+
};
|
436
|
+
|
437
|
+
Browser.prototype.reset = function() {
|
438
|
+
this.resetPage();
|
439
|
+
return this.current_command.sendResponse(true);
|
440
|
+
};
|
441
|
+
|
442
|
+
Browser.prototype.scroll_to = function(left, top) {
|
443
|
+
this.currentPage.setScrollPosition({
|
444
|
+
left: left,
|
445
|
+
top: top
|
446
|
+
});
|
447
|
+
return this.current_command.sendResponse(true);
|
448
|
+
};
|
449
|
+
|
450
|
+
Browser.prototype.send_keys = function(page_id, id, keys) {
|
451
|
+
var i, j, k, key, len, len1, len2, modifier_code, modifier_key, modifier_keys, sequence, target;
|
452
|
+
target = this.node(page_id, id);
|
453
|
+
if (!target.containsSelection()) {
|
454
|
+
target.mouseEvent('click');
|
455
|
+
}
|
456
|
+
for (i = 0, len = keys.length; i < len; i++) {
|
457
|
+
sequence = keys[i];
|
458
|
+
key = sequence.key != null ? this.currentPage.keyCode(sequence.key) : sequence;
|
459
|
+
if (sequence.modifier != null) {
|
460
|
+
modifier_keys = this.currentPage.keyModifierKeys(sequence.modifier);
|
461
|
+
modifier_code = this.currentPage.keyModifierCode(sequence.modifier);
|
462
|
+
for (j = 0, len1 = modifier_keys.length; j < len1; j++) {
|
463
|
+
modifier_key = modifier_keys[j];
|
464
|
+
this.currentPage.sendEvent('keydown', modifier_key);
|
465
|
+
}
|
466
|
+
this.currentPage.sendEvent('keypress', key, null, null, modifier_code);
|
467
|
+
for (k = 0, len2 = modifier_keys.length; k < len2; k++) {
|
468
|
+
modifier_key = modifier_keys[k];
|
469
|
+
this.currentPage.sendEvent('keyup', modifier_key);
|
470
|
+
}
|
471
|
+
} else {
|
472
|
+
this.currentPage.sendEvent('keypress', key);
|
473
|
+
}
|
474
|
+
}
|
475
|
+
return this.current_command.sendResponse(true);
|
476
|
+
};
|
477
|
+
|
478
|
+
Browser.prototype.render_base64 = function(format, full, selector) {
|
479
|
+
var encoded_image;
|
480
|
+
if (selector == null) {
|
481
|
+
selector = null;
|
482
|
+
}
|
483
|
+
this.set_clip_rect(full, selector);
|
484
|
+
encoded_image = this.currentPage.renderBase64(format);
|
485
|
+
return this.current_command.sendResponse(encoded_image);
|
486
|
+
};
|
487
|
+
|
488
|
+
Browser.prototype.render = function(path, full, selector) {
|
489
|
+
var dimensions;
|
490
|
+
if (selector == null) {
|
491
|
+
selector = null;
|
492
|
+
}
|
493
|
+
dimensions = this.set_clip_rect(full, selector);
|
494
|
+
this.currentPage.setScrollPosition({
|
495
|
+
left: 0,
|
496
|
+
top: 0
|
497
|
+
});
|
498
|
+
this.currentPage.render(path);
|
499
|
+
this.currentPage.setScrollPosition({
|
500
|
+
left: dimensions.left,
|
501
|
+
top: dimensions.top
|
502
|
+
});
|
503
|
+
return this.current_command.sendResponse(true);
|
504
|
+
};
|
505
|
+
|
506
|
+
Browser.prototype.set_clip_rect = function(full, selector) {
|
507
|
+
var dimensions, document, rect, ref, viewport;
|
508
|
+
dimensions = this.currentPage.validatedDimensions();
|
509
|
+
ref = [dimensions.document, dimensions.viewport], document = ref[0], viewport = ref[1];
|
510
|
+
rect = full ? {
|
511
|
+
left: 0,
|
512
|
+
top: 0,
|
513
|
+
width: document.width,
|
514
|
+
height: document.height
|
515
|
+
} : selector != null ? this.currentPage.elementBounds(selector) : {
|
516
|
+
left: 0,
|
517
|
+
top: 0,
|
518
|
+
width: viewport.width,
|
519
|
+
height: viewport.height
|
520
|
+
};
|
521
|
+
this.currentPage.setClipRect(rect);
|
522
|
+
return dimensions;
|
523
|
+
};
|
524
|
+
|
525
|
+
Browser.prototype.set_paper_size = function(size) {
|
526
|
+
this.currentPage.setPaperSize(size);
|
527
|
+
return this.current_command.sendResponse(true);
|
528
|
+
};
|
529
|
+
|
530
|
+
Browser.prototype.set_zoom_factor = function(zoom_factor) {
|
531
|
+
this.currentPage.setZoomFactor(zoom_factor);
|
532
|
+
return this.current_command.sendResponse(true);
|
533
|
+
};
|
534
|
+
|
535
|
+
Browser.prototype.resize = function(width, height) {
|
536
|
+
this.currentPage.setViewportSize({
|
537
|
+
width: width,
|
538
|
+
height: height
|
539
|
+
});
|
540
|
+
return this.current_command.sendResponse(true);
|
541
|
+
};
|
542
|
+
|
543
|
+
Browser.prototype.network_traffic = function() {
|
544
|
+
return this.current_command.sendResponse(this.currentPage.networkTraffic());
|
545
|
+
};
|
546
|
+
|
547
|
+
Browser.prototype.clear_network_traffic = function() {
|
548
|
+
this.currentPage.clearNetworkTraffic();
|
549
|
+
return this.current_command.sendResponse(true);
|
550
|
+
};
|
551
|
+
|
552
|
+
Browser.prototype.get_headers = function() {
|
553
|
+
return this.current_command.sendResponse(this.currentPage.getCustomHeaders());
|
554
|
+
};
|
555
|
+
|
556
|
+
Browser.prototype.set_headers = function(headers) {
|
557
|
+
if (headers['User-Agent']) {
|
558
|
+
this.currentPage.setUserAgent(headers['User-Agent']);
|
559
|
+
}
|
560
|
+
this.currentPage.setCustomHeaders(headers);
|
561
|
+
return this.current_command.sendResponse(true);
|
562
|
+
};
|
563
|
+
|
564
|
+
Browser.prototype.add_headers = function(headers) {
|
565
|
+
var allHeaders, name, value;
|
566
|
+
allHeaders = this.currentPage.getCustomHeaders();
|
567
|
+
for (name in headers) {
|
568
|
+
value = headers[name];
|
569
|
+
allHeaders[name] = value;
|
570
|
+
}
|
571
|
+
return this.set_headers(allHeaders);
|
572
|
+
};
|
573
|
+
|
574
|
+
Browser.prototype.add_header = function(header, permanent) {
|
575
|
+
if (!permanent) {
|
576
|
+
this.currentPage.addTempHeader(header);
|
577
|
+
}
|
578
|
+
return this.add_headers(header);
|
579
|
+
};
|
580
|
+
|
581
|
+
Browser.prototype.response_headers = function() {
|
582
|
+
return this.current_command.sendResponse(this.currentPage.responseHeaders());
|
583
|
+
};
|
584
|
+
|
585
|
+
Browser.prototype.cookies = function() {
|
586
|
+
return this.current_command.sendResponse(this.currentPage.cookies());
|
587
|
+
};
|
588
|
+
|
589
|
+
Browser.prototype.set_cookie = function(cookie) {
|
590
|
+
phantom.addCookie(cookie);
|
591
|
+
return this.current_command.sendResponse(true);
|
592
|
+
};
|
593
|
+
|
594
|
+
Browser.prototype.remove_cookie = function(name) {
|
595
|
+
this.currentPage.deleteCookie(name);
|
596
|
+
return this.current_command.sendResponse(true);
|
597
|
+
};
|
598
|
+
|
599
|
+
Browser.prototype.clear_cookies = function() {
|
600
|
+
phantom.clearCookies();
|
601
|
+
return this.current_command.sendResponse(true);
|
602
|
+
};
|
603
|
+
|
604
|
+
Browser.prototype.cookies_enabled = function(flag) {
|
605
|
+
phantom.cookiesEnabled = flag;
|
606
|
+
return this.current_command.sendResponse(true);
|
607
|
+
};
|
608
|
+
|
609
|
+
Browser.prototype.set_http_auth = function(user, password) {
|
610
|
+
this.currentPage.setHttpAuth(user, password);
|
611
|
+
return this.current_command.sendResponse(true);
|
612
|
+
};
|
613
|
+
|
614
|
+
Browser.prototype.set_js_errors = function(value) {
|
615
|
+
this.js_errors = value;
|
616
|
+
return this.current_command.sendResponse(true);
|
617
|
+
};
|
618
|
+
|
619
|
+
Browser.prototype.set_debug = function(value) {
|
620
|
+
this._debug = value;
|
621
|
+
return this.current_command.sendResponse(true);
|
622
|
+
};
|
623
|
+
|
624
|
+
Browser.prototype.exit = function() {
|
625
|
+
return phantom.exit();
|
626
|
+
};
|
627
|
+
|
628
|
+
Browser.prototype.noop = function() {};
|
629
|
+
|
630
|
+
Browser.prototype.browser_error = function() {
|
631
|
+
throw new Error('zomg');
|
632
|
+
};
|
633
|
+
|
634
|
+
Browser.prototype.go_back = function() {
|
635
|
+
var command;
|
636
|
+
command = this.current_command;
|
637
|
+
if (this.currentPage.canGoBack) {
|
638
|
+
this.currentPage.state = 'loading';
|
639
|
+
this.currentPage.goBack();
|
640
|
+
return this.currentPage.waitState('default', (function(_this) {
|
641
|
+
return function() {
|
642
|
+
return command.sendResponse(true);
|
643
|
+
};
|
644
|
+
})(this));
|
645
|
+
} else {
|
646
|
+
return command.sendResponse(false);
|
647
|
+
}
|
648
|
+
};
|
649
|
+
|
650
|
+
Browser.prototype.go_forward = function() {
|
651
|
+
var command;
|
652
|
+
command = this.current_command;
|
653
|
+
if (this.currentPage.canGoForward) {
|
654
|
+
this.currentPage.state = 'loading';
|
655
|
+
this.currentPage.goForward();
|
656
|
+
return this.currentPage.waitState('default', (function(_this) {
|
657
|
+
return function() {
|
658
|
+
return command.sendResponse(true);
|
659
|
+
};
|
660
|
+
})(this));
|
661
|
+
} else {
|
662
|
+
return command.sendResponse(false);
|
663
|
+
}
|
664
|
+
};
|
665
|
+
|
666
|
+
Browser.prototype.set_url_whitelist = function() {
|
667
|
+
this.currentPage.urlWhitelist = Array.prototype.slice.call(arguments);
|
668
|
+
return this.current_command.sendResponse(true);
|
669
|
+
};
|
670
|
+
|
671
|
+
Browser.prototype.set_url_blacklist = function() {
|
672
|
+
this.currentPage.urlBlacklist = Array.prototype.slice.call(arguments);
|
673
|
+
return this.current_command.sendResponse(true);
|
674
|
+
};
|
675
|
+
|
676
|
+
Browser.prototype.set_confirm_process = function(process) {
|
677
|
+
this.confirm_processes.push(process);
|
678
|
+
return this.current_command.sendResponse(true);
|
679
|
+
};
|
680
|
+
|
681
|
+
Browser.prototype.set_prompt_response = function(response) {
|
682
|
+
this.prompt_responses.push(response);
|
683
|
+
return this.current_command.sendResponse(true);
|
684
|
+
};
|
685
|
+
|
686
|
+
Browser.prototype.modal_message = function() {
|
687
|
+
return this.current_command.sendResponse(this.processed_modal_messages.shift());
|
688
|
+
};
|
689
|
+
|
690
|
+
return Browser;
|
691
|
+
|
692
|
+
})();
|