Extension for Chrome does not run

Asked

Viewed 131 times

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 users can share their gmail emails on facebook.

It turns out that importing into Chrome extensions doesn’t happen at all. What I’m doing wrong?

1 answer

1


At first the extension worked normally and makes exactly what you ask for in its manifest, it creates a button with an icon and nothing else, see the image:

exemplo de extensão no chrome

I believe what you want is to use the extensions pop-ups.

In case you added your HTML to background, this means that it will run but will not be displayed. The correct would be to use browser_action.default_popup

Your manifest must be 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 must 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 https://developer.chrome.com/extensions/manifestVersion):

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, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline Execution.

You should move javascript to an isolated JS file and call it that:

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

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

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

Where to start

You should start your studies using the documentation Getting Started: Building a Chrome Extension (is in English, but in Chrome you can translate --it won’t be perfect but it helps)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.