0

I have a manifest file like this:

{
  "name": "Thing",
  "description": "blah blah.",
  "version": "1.0",
  "manifest_version": 2,
  "icons": { 
    "16": "icon-16.png",
    "32": "icon-32.png",
    "180": "icon-180.png" 
  },
  "browser_action": {
    "default_icon": "icon-32.png",
    "default_title": "Fundstack",
    "default_popup": "browser_action/browser_action.html"
  },
  "background": {
    "scripts": [
      "env.js", 
      "node_modules/auth0-chrome/dist/auth0chrome.min.js", 
      "auth.js"
    ],
    "persistent": false
  },
  "content_scripts": [
    {
      "matches": [
        "https://mail.google.com/*",
        "https://inbox.google.com/*"
      ],
      "js": ["vendor/jquery.min.js", "vendor/underscore-min.js", "vendor/moment.min.js", "inboxsdk.js", "content.js", "node_modules/auth0-chrome/dist/auth0chrome.min.js"],
      "css": ["styles.css"],
      "run_at": "document_end"
    }
  ],
  "permissions": [
    "https://mail.google.com/",
    "https://inbox.google.com/",
    "https://logo.clearbit.com/",
    "identity",
    "notifications",
    "activeTab"
  ],
  "web_accessible_resources": [
    "sidebarTemplate.html",
    "icon-*.png"
  ]
}

In browser_action.js I have this:

const loginBtn = $('.login-btn');

loginBtn.click(() => {
    console.log('Click!');
    chrome.runtime.sendMessage({
      type: "authenticate"
    });
});

In auth.js I have this:

chrome.runtime.onMessage.addListener(function(event) {

  console.log('event!!!!');

  return true;

});

When I click I get Click! in the console, though not event!!!!. Am I missing anything obvious?

nick
  • 3,521
  • 3
  • 22
  • 32
  • The background page is a hidden separate page. Make sure you've read the extension architecture article. See [Where to read console messages from background.js in a Chrome extension?](//stackoverflow.com/a/10258029) – wOxxOm Jun 08 '17 at 10:59
  • @wOxxOm Awesome! Thanks! – nick Jun 08 '17 at 11:17
  • sendMessage does not trigger onMessage in the same frame. Use a custom event emitter instead. – Rob W Jun 10 '17 at 16:34

0 Answers0