poltergeist 1.5.1 → 1.6.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.
@@ -44,7 +44,7 @@ PoltergeistAgent = (function() {
44
44
  };
45
45
 
46
46
  PoltergeistAgent.prototype.currentUrl = function() {
47
- return encodeURI(window.location.href);
47
+ return encodeURI(decodeURI(window.location.href));
48
48
  };
49
49
 
50
50
  PoltergeistAgent.prototype.find = function(method, selector, within) {
@@ -89,8 +89,8 @@ PoltergeistAgent = (function() {
89
89
 
90
90
  PoltergeistAgent.prototype.documentSize = function() {
91
91
  return {
92
- height: document.documentElement.scrollHeight,
93
- width: document.documentElement.scrollWidth
92
+ height: document.documentElement.scrollHeight || document.documentElement.clientHeight,
93
+ width: document.documentElement.scrollWidth || document.documentElement.clientWidth
94
94
  };
95
95
  };
96
96
 
@@ -116,6 +116,10 @@ PoltergeistAgent = (function() {
116
116
  return this.get(id).removeAttribute('_poltergeist_selected');
117
117
  };
118
118
 
119
+ PoltergeistAgent.prototype.clearLocalStorage = function() {
120
+ return localStorage.clear();
121
+ };
122
+
119
123
  return PoltergeistAgent;
120
124
 
121
125
  })();
@@ -145,7 +149,8 @@ PoltergeistAgent.InvalidSelector = (function() {
145
149
  PoltergeistAgent.Node = (function() {
146
150
  Node.EVENTS = {
147
151
  FOCUS: ['blur', 'focus', 'focusin', 'focusout'],
148
- MOUSE: ['click', 'dblclick', 'mousedown', 'mouseenter', 'mouseleave', 'mousemove', 'mouseover', 'mouseout', 'mouseup']
152
+ MOUSE: ['click', 'dblclick', 'mousedown', 'mouseenter', 'mouseleave', 'mousemove', 'mouseover', 'mouseout', 'mouseup', 'contextmenu'],
153
+ FORM: ['submit']
149
154
  };
150
155
 
151
156
  function Node(agent, element) {
@@ -157,6 +162,17 @@ PoltergeistAgent.Node = (function() {
157
162
  return this.agent.register(this.element.parentNode);
158
163
  };
159
164
 
165
+ Node.prototype.parentIds = function() {
166
+ var ids, parent;
167
+ ids = [];
168
+ parent = this.element.parentNode;
169
+ while (parent !== document) {
170
+ ids.push(this.agent.register(parent));
171
+ parent = parent.parentNode;
172
+ }
173
+ return ids;
174
+ };
175
+
160
176
  Node.prototype.find = function(method, selector) {
161
177
  return this.agent.find(method, selector, this.element);
162
178
  };
@@ -226,10 +242,12 @@ PoltergeistAgent.Node = (function() {
226
242
  };
227
243
 
228
244
  Node.prototype.visibleText = function() {
229
- if (this.element.nodeName === "TEXTAREA") {
230
- return this.element.textContent;
231
- } else {
232
- return this.element.innerText;
245
+ if (this.isVisible()) {
246
+ if (this.element.nodeName === "TEXTAREA") {
247
+ return this.element.textContent;
248
+ } else {
249
+ return this.element.innerText;
250
+ }
233
251
  }
234
252
  };
235
253
 
@@ -237,10 +255,22 @@ PoltergeistAgent.Node = (function() {
237
255
  var range;
238
256
  range = document.createRange();
239
257
  range.selectNodeContents(this.element);
258
+ window.getSelection().removeAllRanges();
240
259
  window.getSelection().addRange(range);
241
260
  return window.getSelection().deleteFromDocument();
242
261
  };
243
262
 
263
+ Node.prototype.getAttributes = function() {
264
+ var attr, attrs, i, _i, _len, _ref;
265
+ attrs = {};
266
+ _ref = this.element.attributes;
267
+ for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
268
+ attr = _ref[i];
269
+ attrs[attr.name] = attr.value.replace("\n", "\\n");
270
+ }
271
+ return attrs;
272
+ };
273
+
244
274
  Node.prototype.getAttribute = function(name) {
245
275
  if (name === 'checked' || name === 'selected') {
246
276
  return this.element[name];
@@ -340,6 +370,18 @@ PoltergeistAgent.Node = (function() {
340
370
  return this.element.disabled || this.element.tagName === 'OPTION' && this.element.parentNode.disabled;
341
371
  };
342
372
 
373
+ Node.prototype.containsSelection = function() {
374
+ var selectedNode;
375
+ selectedNode = document.getSelection().focusNode;
376
+ if (!selectedNode) {
377
+ return false;
378
+ }
379
+ if (selectedNode.nodeType === 3) {
380
+ selectedNode = selectedNode.parentNode;
381
+ }
382
+ return this.element.contains(selectedNode);
383
+ };
384
+
343
385
  Node.prototype.frameOffset = function() {
344
386
  var offset, rect, style, win;
345
387
  win = window;
@@ -381,14 +423,22 @@ PoltergeistAgent.Node = (function() {
381
423
  event = document.createEvent('MouseEvent');
382
424
  event.initMouseEvent(name, true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
383
425
  } else if (Node.EVENTS.FOCUS.indexOf(name) !== -1) {
384
- event = document.createEvent('HTMLEvents');
385
- event.initEvent(name, true, true);
426
+ event = this.obtainEvent(name);
427
+ } else if (Node.EVENTS.FORM.indexOf(name) !== -1) {
428
+ event = this.obtainEvent(name);
386
429
  } else {
387
430
  throw "Unknown event";
388
431
  }
389
432
  return this.element.dispatchEvent(event);
390
433
  };
391
434
 
435
+ Node.prototype.obtainEvent = function(name) {
436
+ var event;
437
+ event = document.createEvent('HTMLEvents');
438
+ event.initEvent(name, true, true);
439
+ return event;
440
+ };
441
+
392
442
  Node.prototype.mouseEventTest = function(x, y) {
393
443
  var el, frameOffset, origEl;
394
444
  frameOffset = this.frameOffset();
@@ -1,67 +1,53 @@
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
+
1
3
  Poltergeist.Browser = (function() {
2
4
  function Browser(owner, width, height) {
3
5
  this.owner = owner;
4
6
  this.width = width || 1024;
5
7
  this.height = height || 768;
6
- this.state = 'default';
7
- this.page_stack = [];
8
- this.page_id = 0;
8
+ this.pages = [];
9
9
  this.js_errors = true;
10
10
  this._debug = false;
11
+ this._counter = 0;
11
12
  this.resetPage();
12
13
  }
13
14
 
14
15
  Browser.prototype.resetPage = function() {
15
- var _this = this;
16
+ var _ref,
17
+ _this = this;
18
+ _ref = [0, []], this._counter = _ref[0], this.pages = _ref[1];
16
19
  if (this.page != null) {
17
- this.page.release();
20
+ if (!this.page.closed) {
21
+ if (this.page.currentUrl() !== 'about:blank') {
22
+ this.page.clearLocalStorage();
23
+ }
24
+ this.page.release();
25
+ }
18
26
  phantom.clearCookies();
19
27
  }
20
- this.page = new Poltergeist.WebPage;
28
+ this.page = this.currentPage = new Poltergeist.WebPage;
21
29
  this.page.setViewportSize({
22
30
  width: this.width,
23
31
  height: this.height
24
32
  });
25
- this.page.onLoadStarted = function() {
26
- if (_this.state === 'mouse_event') {
27
- return _this.setState('loading');
28
- }
29
- };
30
- this.page.onNavigationRequested = function(url, navigation) {
31
- if (_this.state === 'mouse_event' && navigation === 'FormSubmitted') {
32
- return _this.setState('loading');
33
- }
34
- };
35
- this.page.onLoadFinished = function(status) {
36
- if (_this.state === 'loading') {
37
- _this.sendResponse({
38
- status: status,
39
- position: _this.last_mouse_event
40
- });
41
- return _this.setState('default');
42
- } else if (_this.state === 'awaiting_frame_load') {
43
- _this.sendResponse(true);
44
- return _this.setState('default');
45
- }
46
- };
47
- this.page.onInitialized = function() {
48
- return _this.page_id += 1;
49
- };
50
- return this.page.onPageCreated = function(sub_page) {
51
- var name;
52
- if (_this.state === 'awaiting_sub_page') {
53
- name = _this.page_name;
54
- _this.page_name = null;
55
- _this.setState('default');
56
- return setTimeout((function() {
57
- return _this.push_window(name);
58
- }), 0);
59
- }
33
+ this.page.handle = "" + (this._counter++);
34
+ this.pages.push(this.page);
35
+ return this.page.onPageCreated = function(newPage) {
36
+ var page;
37
+ page = new Poltergeist.WebPage(newPage);
38
+ page.handle = "" + (_this._counter++);
39
+ return _this.pages.push(page);
60
40
  };
61
41
  };
62
42
 
43
+ Browser.prototype.getPageByHandle = function(handle) {
44
+ return this.pages.filter(function(p) {
45
+ return !p.closed && p.handle === handle;
46
+ })[0];
47
+ };
48
+
63
49
  Browser.prototype.runCommand = function(name, args) {
64
- this.setState("default");
50
+ this.currentPage.state = 'default';
65
51
  return this[name].apply(this, args);
66
52
  };
67
53
 
@@ -71,18 +57,10 @@ Poltergeist.Browser = (function() {
71
57
  }
72
58
  };
73
59
 
74
- Browser.prototype.setState = function(state) {
75
- if (this.state === state) {
76
- return;
77
- }
78
- this.debug("state " + this.state + " -> " + state);
79
- return this.state = state;
80
- };
81
-
82
60
  Browser.prototype.sendResponse = function(response) {
83
61
  var errors;
84
- errors = this.page.errors();
85
- this.page.clearErrors();
62
+ errors = this.currentPage.errors;
63
+ this.currentPage.clearErrors();
86
64
  if (errors.length > 0 && this.js_errors) {
87
65
  return this.owner.sendError(new Poltergeist.JavascriptError(errors));
88
66
  } else {
@@ -91,53 +69,66 @@ Poltergeist.Browser = (function() {
91
69
  };
92
70
 
93
71
  Browser.prototype.add_extension = function(extension) {
94
- this.page.injectExtension(extension);
72
+ this.currentPage.injectExtension(extension);
95
73
  return this.sendResponse('success');
96
74
  };
97
75
 
98
76
  Browser.prototype.node = function(page_id, id) {
99
- if (page_id === this.page_id) {
100
- return this.page.get(id);
77
+ if (this.currentPage.id === page_id) {
78
+ return this.currentPage.get(id);
101
79
  } else {
102
80
  throw new Poltergeist.ObsoleteNode;
103
81
  }
104
82
  };
105
83
 
106
84
  Browser.prototype.visit = function(url) {
107
- var prev_url;
108
- this.setState('loading');
109
- prev_url = this.page.source() === null ? 'about:blank' : this.page.currentUrl();
110
- this.page.open(url);
111
- if (/#/.test(url) && prev_url.split('#')[0] === url.split('#')[0]) {
112
- this.setState('default');
113
- return this.sendResponse('success');
85
+ var prevUrl,
86
+ _this = this;
87
+ this.currentPage.state = 'loading';
88
+ prevUrl = this.currentPage.source === null ? 'about:blank' : this.currentPage.currentUrl();
89
+ this.currentPage.open(url);
90
+ if (/#/.test(url) && prevUrl.split('#')[0] === url.split('#')[0]) {
91
+ this.currentPage.state = 'default';
92
+ return this.sendResponse({
93
+ status: 'success'
94
+ });
95
+ } else {
96
+ return this.currentPage.waitState('default', function() {
97
+ if (_this.currentPage.statusCode === null && _this.currentPage.status === 'fail') {
98
+ return _this.owner.sendError(new Poltergeist.StatusFailError);
99
+ } else {
100
+ return _this.sendResponse({
101
+ status: _this.currentPage.status
102
+ });
103
+ }
104
+ });
114
105
  }
115
106
  };
116
107
 
117
108
  Browser.prototype.current_url = function() {
118
- return this.sendResponse(this.page.currentUrl());
109
+ return this.sendResponse(this.currentPage.currentUrl());
119
110
  };
120
111
 
121
112
  Browser.prototype.status_code = function() {
122
- return this.sendResponse(this.page.statusCode());
113
+ return this.sendResponse(this.currentPage.statusCode);
123
114
  };
124
115
 
125
116
  Browser.prototype.body = function() {
126
- return this.sendResponse(this.page.content());
117
+ return this.sendResponse(this.currentPage.content());
127
118
  };
128
119
 
129
120
  Browser.prototype.source = function() {
130
- return this.sendResponse(this.page.source());
121
+ return this.sendResponse(this.currentPage.source);
131
122
  };
132
123
 
133
124
  Browser.prototype.title = function() {
134
- return this.sendResponse(this.page.title());
125
+ return this.sendResponse(this.currentPage.title());
135
126
  };
136
127
 
137
128
  Browser.prototype.find = function(method, selector) {
138
129
  return this.sendResponse({
139
- page_id: this.page_id,
140
- ids: this.page.find(method, selector)
130
+ page_id: this.currentPage.id,
131
+ ids: this.currentPage.find(method, selector)
141
132
  });
142
133
  };
143
134
 
@@ -161,6 +152,14 @@ Poltergeist.Browser = (function() {
161
152
  return this.sendResponse(this.node(page_id, id).getAttribute(name));
162
153
  };
163
154
 
155
+ Browser.prototype.attributes = function(page_id, id, name) {
156
+ return this.sendResponse(this.node(page_id, id).getAttributes());
157
+ };
158
+
159
+ Browser.prototype.parents = function(page_id, id) {
160
+ return this.sendResponse(this.node(page_id, id).parentIds());
161
+ };
162
+
164
163
  Browser.prototype.value = function(page_id, id) {
165
164
  return this.sendResponse(this.node(page_id, id).value());
166
165
  };
@@ -173,9 +172,9 @@ Poltergeist.Browser = (function() {
173
172
  Browser.prototype.select_file = function(page_id, id, value) {
174
173
  var node;
175
174
  node = this.node(page_id, id);
176
- this.page.beforeUpload(node.id);
177
- this.page.uploadFile('[_poltergeist_selected]', value);
178
- this.page.afterUpload(node.id);
175
+ this.currentPage.beforeUpload(node.id);
176
+ this.currentPage.uploadFile('[_poltergeist_selected]', value);
177
+ this.currentPage.afterUpload(node.id);
179
178
  return this.sendResponse(true);
180
179
  };
181
180
 
@@ -196,22 +195,32 @@ Poltergeist.Browser = (function() {
196
195
  };
197
196
 
198
197
  Browser.prototype.evaluate = function(script) {
199
- return this.sendResponse(this.page.evaluate("function() { return " + script + " }"));
198
+ return this.sendResponse(this.currentPage.evaluate("function() { return " + script + " }"));
200
199
  };
201
200
 
202
201
  Browser.prototype.execute = function(script) {
203
- this.page.execute("function() { " + script + " }");
202
+ this.currentPage.execute("function() { " + script + " }");
204
203
  return this.sendResponse(true);
205
204
  };
206
205
 
206
+ Browser.prototype.frameUrl = function(frame_name) {
207
+ return this.currentPage.frameUrl(frame_name);
208
+ };
209
+
207
210
  Browser.prototype.push_frame = function(name, timeout) {
208
- var _this = this;
211
+ var _ref,
212
+ _this = this;
209
213
  if (timeout == null) {
210
214
  timeout = new Date().getTime() + 2000;
211
215
  }
212
- if (this.page.pushFrame(name)) {
213
- if (this.page.currentUrl() === 'about:blank') {
214
- return this.setState('awaiting_frame_load');
216
+ if (_ref = this.frameUrl(name), __indexOf.call(this.currentPage.blockedUrls(), _ref) >= 0) {
217
+ return this.sendResponse(true);
218
+ } else if (this.currentPage.pushFrame(name)) {
219
+ if (this.currentPage.currentUrl() === 'about:blank') {
220
+ this.currentPage.state = 'awaiting_frame_load';
221
+ return this.currentPage.waitState('default', function() {
222
+ return _this.sendResponse(true);
223
+ });
215
224
  } else {
216
225
  return this.sendResponse(true);
217
226
  }
@@ -226,55 +235,83 @@ Poltergeist.Browser = (function() {
226
235
  }
227
236
  };
228
237
 
229
- Browser.prototype.pages = function() {
230
- return this.sendResponse(this.page.pages());
238
+ Browser.prototype.pop_frame = function() {
239
+ return this.sendResponse(this.currentPage.popFrame());
240
+ };
241
+
242
+ Browser.prototype.window_handles = function() {
243
+ var handles;
244
+ handles = this.pages.filter(function(p) {
245
+ return !p.closed;
246
+ }).map(function(p) {
247
+ return p.handle;
248
+ });
249
+ return this.sendResponse(handles);
231
250
  };
232
251
 
233
- Browser.prototype.pop_frame = function() {
234
- return this.sendResponse(this.page.popFrame());
252
+ Browser.prototype.window_handle = function(name) {
253
+ var handle, page;
254
+ if (name == null) {
255
+ name = null;
256
+ }
257
+ handle = name ? (page = this.pages.filter(function(p) {
258
+ return !p.closed && p.windowName() === name;
259
+ })[0], page ? page.handle : null) : this.currentPage.handle;
260
+ return this.sendResponse(handle);
235
261
  };
236
262
 
237
- Browser.prototype.push_window = function(name) {
238
- var sub_page,
263
+ Browser.prototype.switch_to_window = function(handle) {
264
+ var page,
239
265
  _this = this;
240
- sub_page = this.page.getPage(name);
241
- if (sub_page) {
242
- if (sub_page.currentUrl() === 'about:blank') {
243
- return sub_page.onLoadFinished = function() {
244
- sub_page.onLoadFinished = null;
245
- return _this.push_window(name);
246
- };
266
+ page = this.getPageByHandle(handle);
267
+ if (page) {
268
+ if (page !== this.currentPage) {
269
+ return page.waitState('default', function() {
270
+ _this.currentPage = page;
271
+ return _this.sendResponse(true);
272
+ });
247
273
  } else {
248
- this.page_stack.push(this.page);
249
- this.page = sub_page;
250
- this.page_id += 1;
251
274
  return this.sendResponse(true);
252
275
  }
253
276
  } else {
254
- this.page_name = name;
255
- return this.setState('awaiting_sub_page');
277
+ throw new Poltergeist.NoSuchWindowError;
256
278
  }
257
279
  };
258
280
 
259
- Browser.prototype.pop_window = function() {
260
- var prev_page;
261
- prev_page = this.page_stack.pop();
262
- if (prev_page) {
263
- this.page = prev_page;
264
- }
281
+ Browser.prototype.open_new_window = function() {
282
+ this.execute('window.open()');
265
283
  return this.sendResponse(true);
266
284
  };
267
285
 
286
+ Browser.prototype.close_window = function(handle) {
287
+ var page;
288
+ page = this.getPageByHandle(handle);
289
+ if (page) {
290
+ page.release();
291
+ return this.sendResponse(true);
292
+ } else {
293
+ return this.sendResponse(false);
294
+ }
295
+ };
296
+
268
297
  Browser.prototype.mouse_event = function(page_id, id, name) {
269
298
  var node,
270
299
  _this = this;
271
300
  node = this.node(page_id, id);
272
- this.setState('mouse_event');
301
+ this.currentPage.state = 'mouse_event';
273
302
  this.last_mouse_event = node.mouseEvent(name);
274
303
  return setTimeout(function() {
275
- if (_this.state !== 'loading') {
276
- _this.setState('default');
277
- return _this.sendResponse(_this.last_mouse_event);
304
+ if (_this.currentPage.state === 'mouse_event') {
305
+ _this.currentPage.state = 'default';
306
+ return _this.sendResponse({
307
+ position: _this.last_mouse_event
308
+ });
309
+ } else {
310
+ return _this.currentPage.waitState('default', function() {
311
+ return _this.sendResponse({
312
+ position: _this.last_mouse_event
313
+ });
314
+ });
278
315
  }
279
316
  }, 5);
280
317
  };
@@ -283,6 +320,10 @@ Poltergeist.Browser = (function() {
283
320
  return this.mouse_event(page_id, id, 'click');
284
321
  };
285
322
 
323
+ Browser.prototype.right_click = function(page_id, id) {
324
+ return this.mouse_event(page_id, id, 'rightclick');
325
+ };
326
+
286
327
  Browser.prototype.double_click = function(page_id, id) {
287
328
  return this.mouse_event(page_id, id, 'doubleclick');
288
329
  };
@@ -292,7 +333,7 @@ Poltergeist.Browser = (function() {
292
333
  };
293
334
 
294
335
  Browser.prototype.click_coordinates = function(x, y) {
295
- this.page.sendEvent('click', x, y);
336
+ this.currentPage.sendEvent('click', x, y);
296
337
  return this.sendResponse({
297
338
  click: {
298
339
  x: x,
@@ -321,7 +362,7 @@ Poltergeist.Browser = (function() {
321
362
  };
322
363
 
323
364
  Browser.prototype.scroll_to = function(left, top) {
324
- this.page.setScrollPosition({
365
+ this.currentPage.setScrollPosition({
325
366
  left: left,
326
367
  top: top
327
368
  });
@@ -329,12 +370,15 @@ Poltergeist.Browser = (function() {
329
370
  };
330
371
 
331
372
  Browser.prototype.send_keys = function(page_id, id, keys) {
332
- var key, sequence, _i, _len;
333
- this.node(page_id, id).mouseEvent('click');
373
+ var key, sequence, target, _i, _len;
374
+ target = this.node(page_id, id);
375
+ if (!target.containsSelection()) {
376
+ target.mouseEvent('click');
377
+ }
334
378
  for (_i = 0, _len = keys.length; _i < _len; _i++) {
335
379
  sequence = keys[_i];
336
- key = sequence.key != null ? this.page["native"].event.key[sequence.key] : sequence;
337
- this.page.sendEvent('keypress', key);
380
+ key = sequence.key != null ? this.currentPage.keyCode(sequence.key) : sequence;
381
+ this.currentPage.sendEvent('keypress', key);
338
382
  }
339
383
  return this.sendResponse(true);
340
384
  };
@@ -345,7 +389,7 @@ Poltergeist.Browser = (function() {
345
389
  selector = null;
346
390
  }
347
391
  this.set_clip_rect(full, selector);
348
- encoded_image = this.page.renderBase64(format);
392
+ encoded_image = this.currentPage.renderBase64(format);
349
393
  return this.sendResponse(encoded_image);
350
394
  };
351
395
 
@@ -355,12 +399,12 @@ Poltergeist.Browser = (function() {
355
399
  selector = null;
356
400
  }
357
401
  dimensions = this.set_clip_rect(full, selector);
358
- this.page.setScrollPosition({
402
+ this.currentPage.setScrollPosition({
359
403
  left: 0,
360
404
  top: 0
361
405
  });
362
- this.page.render(path);
363
- this.page.setScrollPosition({
406
+ this.currentPage.render(path);
407
+ this.currentPage.setScrollPosition({
364
408
  left: dimensions.left,
365
409
  top: dimensions.top
366
410
  });
@@ -369,30 +413,35 @@ Poltergeist.Browser = (function() {
369
413
 
370
414
  Browser.prototype.set_clip_rect = function(full, selector) {
371
415
  var dimensions, document, rect, viewport, _ref;
372
- dimensions = this.page.validatedDimensions();
416
+ dimensions = this.currentPage.validatedDimensions();
373
417
  _ref = [dimensions.document, dimensions.viewport], document = _ref[0], viewport = _ref[1];
374
418
  rect = full ? {
375
419
  left: 0,
376
420
  top: 0,
377
421
  width: document.width,
378
422
  height: document.height
379
- } : selector != null ? this.page.elementBounds(selector) : {
423
+ } : selector != null ? this.currentPage.elementBounds(selector) : {
380
424
  left: 0,
381
425
  top: 0,
382
426
  width: viewport.width,
383
427
  height: viewport.height
384
428
  };
385
- this.page.setClipRect(rect);
429
+ this.currentPage.setClipRect(rect);
386
430
  return dimensions;
387
431
  };
388
432
 
389
433
  Browser.prototype.set_paper_size = function(size) {
390
- this.page.setPaperSize(size);
434
+ this.currentPage.setPaperSize(size);
435
+ return this.sendResponse(true);
436
+ };
437
+
438
+ Browser.prototype.set_zoom_factor = function(zoom_factor) {
439
+ this.currentPage.setZoomFactor(zoom_factor);
391
440
  return this.sendResponse(true);
392
441
  };
393
442
 
394
443
  Browser.prototype.resize = function(width, height) {
395
- this.page.setViewportSize({
444
+ this.currentPage.setViewportSize({
396
445
  width: width,
397
446
  height: height
398
447
  });
@@ -400,29 +449,29 @@ Poltergeist.Browser = (function() {
400
449
  };
401
450
 
402
451
  Browser.prototype.network_traffic = function() {
403
- return this.sendResponse(this.page.networkTraffic());
452
+ return this.sendResponse(this.currentPage.networkTraffic());
404
453
  };
405
454
 
406
455
  Browser.prototype.clear_network_traffic = function() {
407
- this.page.clearNetworkTraffic();
456
+ this.currentPage.clearNetworkTraffic();
408
457
  return this.sendResponse(true);
409
458
  };
410
459
 
411
460
  Browser.prototype.get_headers = function() {
412
- return this.sendResponse(this.page.getCustomHeaders());
461
+ return this.sendResponse(this.currentPage.getCustomHeaders());
413
462
  };
414
463
 
415
464
  Browser.prototype.set_headers = function(headers) {
416
465
  if (headers['User-Agent']) {
417
- this.page.setUserAgent(headers['User-Agent']);
466
+ this.currentPage.setUserAgent(headers['User-Agent']);
418
467
  }
419
- this.page.setCustomHeaders(headers);
468
+ this.currentPage.setCustomHeaders(headers);
420
469
  return this.sendResponse(true);
421
470
  };
422
471
 
423
472
  Browser.prototype.add_headers = function(headers) {
424
473
  var allHeaders, name, value;
425
- allHeaders = this.page.getCustomHeaders();
474
+ allHeaders = this.currentPage.getCustomHeaders();
426
475
  for (name in headers) {
427
476
  value = headers[name];
428
477
  allHeaders[name] = value;
@@ -432,17 +481,17 @@ Poltergeist.Browser = (function() {
432
481
 
433
482
  Browser.prototype.add_header = function(header, permanent) {
434
483
  if (!permanent) {
435
- this.page.addTempHeader(header);
484
+ this.currentPage.addTempHeader(header);
436
485
  }
437
486
  return this.add_headers(header);
438
487
  };
439
488
 
440
489
  Browser.prototype.response_headers = function() {
441
- return this.sendResponse(this.page.responseHeaders());
490
+ return this.sendResponse(this.currentPage.responseHeaders());
442
491
  };
443
492
 
444
493
  Browser.prototype.cookies = function() {
445
- return this.sendResponse(this.page.cookies());
494
+ return this.sendResponse(this.currentPage.cookies());
446
495
  };
447
496
 
448
497
  Browser.prototype.set_cookie = function(cookie) {
@@ -451,7 +500,12 @@ Poltergeist.Browser = (function() {
451
500
  };
452
501
 
453
502
  Browser.prototype.remove_cookie = function(name) {
454
- this.page.deleteCookie(name);
503
+ this.currentPage.deleteCookie(name);
504
+ return this.sendResponse(true);
505
+ };
506
+
507
+ Browser.prototype.clear_cookies = function() {
508
+ phantom.clearCookies();
455
509
  return this.sendResponse(true);
456
510
  };
457
511
 
@@ -461,7 +515,7 @@ Poltergeist.Browser = (function() {
461
515
  };
462
516
 
463
517
  Browser.prototype.set_http_auth = function(user, password) {
464
- this.page.setHttpAuth(user, password);
518
+ this.currentPage.setHttpAuth(user, password);
465
519
  return this.sendResponse(true);
466
520
  };
467
521
 
@@ -486,16 +540,33 @@ Poltergeist.Browser = (function() {
486
540
  };
487
541
 
488
542
  Browser.prototype.go_back = function() {
489
- if (this.page.canGoBack) {
490
- this.page.goBack();
543
+ var _this = this;
544
+ if (this.currentPage.canGoBack) {
545
+ this.currentPage.state = 'loading';
546
+ this.currentPage.goBack();
547
+ return this.currentPage.waitState('default', function() {
548
+ return _this.sendResponse(true);
549
+ });
550
+ } else {
551
+ return this.sendResponse(false);
491
552
  }
492
- return this.sendResponse(true);
493
553
  };
494
554
 
495
555
  Browser.prototype.go_forward = function() {
496
- if (this.page.canGoForward) {
497
- this.page.goForward();
556
+ var _this = this;
557
+ if (this.currentPage.canGoForward) {
558
+ this.currentPage.state = 'loading';
559
+ this.currentPage.goForward();
560
+ return this.currentPage.waitState('default', function() {
561
+ return _this.sendResponse(true);
562
+ });
563
+ } else {
564
+ return this.sendResponse(false);
498
565
  }
566
+ };
567
+
568
+ Browser.prototype.set_url_blacklist = function() {
569
+ this.currentPage.urlBlacklist = Array.prototype.slice.call(arguments);
499
570
  return this.sendResponse(true);
500
571
  };
501
572