我有一个这样的清单文件:
{
"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"
]
}
在browser_action.js
我有这个:
const loginBtn = $('.login-btn');
loginBtn.click(() => {
console.log('Click!');
chrome.runtime.sendMessage({
type: "authenticate"
});
});
在auth.js
我有这个:
chrome.runtime.onMessage.addListener(function(event) {
console.log('event!!!!');
return true;
});
当我点击时,我在控制台中获得Click!
,但不是event!!!!
。我错过了什么明显的东西?