Search code examples
facebookgoogle-chromegoogle-chrome-extensionfacebook-like

How can I add a facebook like button to my chrome extension


I want to add a facebook like button to my chrome extension but I get an error while attempting this. Here is my manifest file:

{
  "name": "XXXXX",
  "manifest_version": 2,
  "version": "1.9",


  "icons":      { "128": "images/xxx.png" },

  "background": {
    "scripts": ["background.js"],
    "page": "background.html"
  },

  "permissions": [
  "tabs","bookmarks",
  "http://*/*",
  "https://*/*"],

  "background": { "page": "background.html"},

  "web_accessible_resources": [
     "images/info.png"
  ],

  "browser_action": {
    "default_title": "Xxx",
    "default_icon": "images/xxxx.png",
    "default_popup": "list.html"
  }

}

This is the frame that I want to add:

<iframe src="//www.facebook.com/plugins/like.php?href=https%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2Fplugins%2F&amp;width&amp;layout=standard&amp;action=like&amp;show_faces=true&amp;share=true&amp;height=80&amp;appId=229499750441210" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:80px;" allowTransparency="true"></iframe>

What should I do in order to get ride of the following error:

GET chrome-extension://www.facebook.com/plugins/like.php?href=https%3A%2F%2Fdev…ard&action=like&show_faces=true&share=true&height=80&appId=229499750441210 net::ERR_FAILED

Solution

  • Note how it's attempting to use chrome-extension://www.facebook.com as the URL? That's because starting a URL with // tells the browser to use the current protocol. Since Chrome extensions use the protocol chrome-extension it doesn't work.

    Try updating the iframe to be

    <iframe src="https://www.facebook.com/plugins/like.php?href=https%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2Fplugins%2F&amp;width&amp;layout=standard&amp;action=like&amp;show_faces=true&amp;share=true&amp;height=80&amp;appId=229499750441210" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:80px;" allowTransparency="true"></iframe>