refs #114 - ensure client utils are always injected when calling Casper.evaluate()
Showing
1 changed file
with
4 additions
and
2 deletions
... | @@ -156,7 +156,6 @@ Casper.prototype.back = function back() { | ... | @@ -156,7 +156,6 @@ Casper.prototype.back = function back() { |
156 | * @return string Base64 encoded result | 156 | * @return string Base64 encoded result |
157 | */ | 157 | */ |
158 | Casper.prototype.base64encode = function base64encode(url, method, data) { | 158 | Casper.prototype.base64encode = function base64encode(url, method, data) { |
159 | this.injectClientUtils(); | ||
160 | return this.evaluate(function _evaluate(url, method, data) { | 159 | return this.evaluate(function _evaluate(url, method, data) { |
161 | return __utils__.getBase64(url, method, data); | 160 | return __utils__.getBase64(url, method, data); |
162 | }, { url: url, method: method, data: data }); | 161 | }, { url: url, method: method, data: data }); |
... | @@ -422,6 +421,9 @@ Casper.prototype.echo = function echo(text, style, pad) { | ... | @@ -422,6 +421,9 @@ Casper.prototype.echo = function echo(text, style, pad) { |
422 | * @see WebPage#evaluate | 421 | * @see WebPage#evaluate |
423 | */ | 422 | */ |
424 | Casper.prototype.evaluate = function evaluate(fn, context) { | 423 | Casper.prototype.evaluate = function evaluate(fn, context) { |
424 | // ensure client utils are always injected | ||
425 | this.injectClientUtils(); | ||
426 | // function processing | ||
425 | context = utils.isObject(context) ? context : {}; | 427 | context = utils.isObject(context) ? context : {}; |
426 | var newFn = require('injector').create(fn).process(context); | 428 | var newFn = require('injector').create(fn).process(context); |
427 | return this.page.evaluate(newFn); | 429 | return this.page.evaluate(newFn); |
... | @@ -625,7 +627,7 @@ Casper.prototype.getTitle = function getTitle() { | ... | @@ -625,7 +627,7 @@ Casper.prototype.getTitle = function getTitle() { |
625 | * | 627 | * |
626 | */ | 628 | */ |
627 | Casper.prototype.injectClientUtils = function injectClientUtils() { | 629 | Casper.prototype.injectClientUtils = function injectClientUtils() { |
628 | var clientUtilsInjected = this.evaluate(function() { | 630 | var clientUtilsInjected = this.page.evaluate(function() { |
629 | return typeof __utils__ === "object"; | 631 | return typeof __utils__ === "object"; |
630 | }); | 632 | }); |
631 | if (true === clientUtilsInjected) { | 633 | if (true === clientUtilsInjected) { | ... | ... |
-
Please register or sign in to post a comment