javascript - CasperJS bind issue -
i'm trying reach instagram page, no luck. keep getting error , blank screenshot.
error text:
typeerror: 'undefined' not function (evaluating 'a.createdescriptor.bind(null,t)')
casperjs --version 1.1.0-beta3.
basically use following code:
var casper = require('casper').create({ verbose: true, loglevel: 'debug', pagesettings: { useragent: 'mozilla/5.0 (macintosh; intel mac os x 10_7_5) applewebkit/537.4 (khtml, gecko) chrome/22.0.1229.94 safari/537.4' }, loadplugins: true }); casper.on( 'page.error', function (msg, trace) { this.echo( 'error: ' + msg, 'error' ); }); casper.start('http://instagram.com/hello', function() { casper.wait(3000, function() { this.capture('screen.png'); }); }); casper.run(function() { this.exit(); });
the shim below isn't needed anymore if phantomjs 2 used. sadly casperjs 1.1-beta3 doesn't support yet, might want use master branch github.
the problem phantomjs v1.x not support function.prototype.bind
. need add shim that. in casperjs goes page.initialized
event handler. this shim works me on instragram:
casper.on( 'page.initialized', function(){ this.evaluate(function(){ var isfunction = function(o) { return typeof o == 'function'; }; var bind, slice = [].slice, proto = function.prototype, featuremap; featuremap = { 'function-bind': 'bind' }; function has(feature) { var prop = featuremap[feature]; return isfunction(proto[prop]); } // check missing features if (!has('function-bind')) { // adapted mozilla developer network example @ // https://developer.mozilla.org/en/javascript/reference/global_objects/function/bind bind = function bind(obj) { var args = slice.call(arguments, 1), self = this, nop = function() { }, bound = function() { return self.apply(this instanceof nop ? : (obj || {}), args.concat(slice.call(arguments))); }; nop.prototype = this.prototype || {}; // firefox cries if prototype undefined bound.prototype = new nop(); return bound; }; proto.bind = bind; } }); });
it doesn't work if shim exported own file , included through clientscripts
option, because appended after instagram javascript late.
what might work registering page.resource.received
event.
there pure phantomjs question: bind polyfill phantomjs
Comments
Post a Comment