Twitter embed widget doesn't load on PhantomJS 1.9.8


I’ve been using PhantomJS to create PDF reports for clients about their social media profiles for the past year or so and it’s been working fine (with the exception of a small change needed when SSLv3 was disabled)

However since sometime in January the embedded widget no longer renders. I’ve tried a few basic things (removing the async, increasing render wait time, checking for JS & network errors) however there seems to be no problems indicated anywhere apart from the fact it simply doesn’t load. Also, the twttr object is never created on window either, so it seems the script is either not running or is quitting out quite soon into execution.

This does seem to be limited to PhantomJS pre-2.0.0, however there are a few bugs in 2.0.0 which are preventing us from upgrading for the time being.

Does anyone know of a solution to this problem?



Phantom has a strange inconsistency with our supported browsers whereby it doesn’t have Function.prototype.bind implemented, which we use. You can make widgets work in Phantom (we use it for all of our unit testing internally) by adding a polyfill for bind to your environment. We use the one documented on

if (!Function.prototype.bind) {
  Function.prototype.bind = function(oThis) {
    if (typeof this !== 'function') {
      // closest thing possible to the ECMAScript 5
      // internal IsCallable function
      throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');

    var aArgs   =, 1),
        fToBind = this,
        fNOP    = function() {},
        fBound  = function() {
          return fToBind.apply(this instanceof fNOP && oThis
                 ? this
                 : oThis,

    fNOP.prototype = this.prototype;
    fBound.prototype = new fNOP();

    return fBound;



Ah that’s perfect! Thank you very much!