Extension for Chrome does not run

0

Manifest:

{
  "manifest_version": 2,

  "name": "Gmail Extension",
  "version": "1.0",
  "description": "Share your mail from Gmail on facebook.",

  "browser_action": {
    "default_icon": "gmail.png"
  },

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

  "permissions": ["<all_urls>"]
}

background.html:

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/pt_PT/sdk.js#xfbml=1&appId=326350284188834&version=v2.0";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-share-button" data-href="https://developers.facebook.com/docs/plugins/" data-layout="button"></div>
</body>
</html>

I'm trying to make a Chrome extension so that users can share their gmail emails on facebook.

It turns out that when importing to Chrome extensions nothing happens. What am I doing wrong?

    
asked by anonymous 28.12.2014 / 20:03

1 answer

1

At first the extension worked normally and does exactly what you request in your manifest, it creates a button with an icon and nothing else, see the image:

Ibelieveyouwanttouseextensionspopups.

IncaseyouaddedyourHTMLtobackground,itmeansthatitwillrun,butitwillnotbedisplayed.Thecorrectonewouldbetouse browser_action.default_popup

Your manifest should look something like:

{
    "manifest_version": 2,
    "name": "Gmail Extension test",
    "version": "1.0",
    "description": "Share your mail from Gmail on facebook.",
    "browser_action": {
        "default_icon": "gmail.png",
        "default_popup":"background.html"
    },
    "permissions": ["<all_urls>"]
}

Note that you should change this line

js.src = "//connect.facebook.net/pt_PT/sdk.js#xfbml=1&appId=326350284188834&version=v2.0";

for

js.src = "http://connect.facebook.net/pt_PT/sdk.js#xfbml=1&appId=326350284188834&version=v2.0";

Note that your html is causing a security problem (read on link ):

  

Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' chrome-extension-resource:". Either the 'unsafe-inline' keyword, the hash ('sha256 -...'), or a nonce ('nonce -...') is required to enable inline execution.

You should move the javascript to an isolated JS file and call it like this:

<script src="meu-javascript.js"></script>

And in case you are using an external extension from the domain http://connect.facebook.com.br , you should add to this:

{
...
    "content_security_policy": "script-src 'self' 'unsafe-eval' http://*.facebook.net; object-src 'self'"
}

Where to start

You should start your studies by using the Getting Started: Building a Chrome Extension documentation. Chrome you can translate - will not be perfect but help)

    
29.12.2014 / 04:31