Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I try to add simple Like button to my Facebook Canvas app (iframe). The button (and all other XFBML elements) works in Safari, Firefox, Opera, but in Google Chrome.

How can I find the problem?


This is ERB-layout in my Rails app

<html xmlns:fb='http://www.facebook.com/2008/fbml' xmlns='http://www.w3.org/1999/xhtml'>
<div id="fb-root"></div>
    window.fbAsyncInit = function() {
        appId: '<%= @app_id %>', status: true, cookie: true, xfbml: true
    (function() {
      var e = document.createElement('script'); e.async = true;
      e.src = document.location.protocol +

JS error message in Chrome inspector:

Uncaught ReferenceError: FB is not defined
  (anonymous function)
Uncaught TypeError: Cannot call method 'appendChild' of null
  (anonymous function)

Probably similar to http://forum.developers.facebook.net/viewtopic.php?id=84684

share|improve this question
I've had similar problems. Are you using any extension? – Agos Jan 13 '11 at 10:12
@Agos, you are right - it was FB Disconnect :). Very stupid. I was testing it Incognito mode, where all ext-s are off. That time there was another error so I thought that it something in JS. Do'h!.. – Andrei Jan 13 '11 at 10:44
up vote 1 down vote accepted

I'm doing exaclty what you are doing. And it works. Try this snippet.

<div id="fb-root"></div>

<script src="http://connect.facebook.net/en_US/all.js"></script>


  FB.init({appId: '<%= @app_id %>', status: true, cookie: true, xfbml: true});

  FB.Event.subscribe('auth.sessionChange', function(response) {

    if (response.session) {

      // A user has logged in, and a new cookie has been saved

    } else {

      // The user has logged out, and the cookie has been cleared



share|improve this answer
the same error. very weird problem. – Andrei Jan 12 '11 at 23:30
hmm..but you should have the xmlns:fb after the xmlns.. i will look into it.. – andrewk Jan 13 '11 at 0:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.