Uncaught TypeError: Cannot call method 'shift' of null for Facebook JS library in Chrome

1.2k views Asked by At

The below Facebook initialization code is resulting in a JS error on page load in Chrome: Uncaught TypeError: Cannot call method 'shift' of null.

  window.fbAsyncInit = function() {
    FB.init({
      appId      : '...',
      status     : true,
      xfbml      : true
    });
  };
  (function(){
    if (document.getElementById('facebook-jssdk')) {return;}
    var firstScriptElement = document.getElementsByTagName('script')[0];
    var facebookJS = document.createElement('script'); 
    facebookJS.id = 'facebook-jssdk';
    facebookJS.src = '//connect.facebook.net/en_US/all.js';
    firstScriptElement.parentNode.insertBefore(facebookJS, firstScriptElement);
  }());
1

There are 1 answers

0
Rajan On

I had the same issue, and I solved by adding the Facebook JS at the top of body, just after the <body> tag as said on the Facebook documentation

I was using version: v2.2

Look basic setup on Facbook Javascript SDK