我正在构建一个Chrome扩展,当用户单击扩展图标时,它会注入一些HTML和JS。因此,当单击图标时,它将在bg脚本中注册,并通知内容脚本如下:
后台脚本
chrome.browserAction.onClicked.addListener(iconClicked)
function iconClicked(tab) {
var visitors = window.AllVisitors.get(tab.id),
data = {
message: 'toggleMenu',
user: window.user
};
chrome.tabs.sendMessage(tab.id, data);
}现在,对于问题:在我的清单文件中,我还为chrome://newtab页面添加了一个自定义页面。当访问自定义的newtab页面时单击扩展图标时,内容脚本将不会收到任何消息。默认的newtab页面实际上接收消息以及任何其他网页。
我认为这可能与externally_connectable有关,但补充说这一点没有帮助:
"externally_connectable": {
"matches": ["chrome://newtab/"],
}有人知道为什么我的自定义newtab页面没有从后台脚本接收到任何消息吗?任何帮助都是非常感谢的!
报表文件:
{
"manifest_version": 2,
"name": "Orbit",
"version": "0.0.1",
"web_accessible_resources": [
"templates.html",
"img/icon48.png",
"fonts/*.woff",
"img/*"
],
"externally_connectable": {
"matches": ["chrome://newtab/"],
},
"chrome_url_overrides" : {
"newtab": "tab/newtab.html"
},
"icons": {
"16": "img/icon16.png",
"48": "img/icon48.png",
"128": "img/icon128.png"
},
"browser_action": {
"default_icon": {
"16": "img/icon16.png",
"48": "img/icon48.png",
"128": "img/icon128.png"
},
"default_title": "Orbit"
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["vendor/chrome-promise.js", "vendor/jquery.js", "vendor/underscore.js", "vendor/backbone.js", "orbit.js"]
},
{
"matches": ["<all_urls>"],
"css": ["sidebar.css"]
}
],
"background": {
"scripts": ["vendor/socket.io.js", "vendor/jquery.js", "vendor/underscore.js", "vendor/backbone.js", "vendor/chrome-promise.js", "vendor/jquery.js", "eventPage.js"],
"persistent": true
},
"permissions": [
"http://fonts.googleapis.com/*",
"https://fonts.googleapis.com/*",
"https://get-orbit.com:8080/*",
"activeTab",
"tabs",
"storage"
]
}发布于 2015-09-16 00:03:09
内容脚本不会注入到chrome-extension://页面中。
只需在newtab.html中手动添加脚本:
<html>
<head>
<script src="your-content-script.js"></script>
</head>https://stackoverflow.com/questions/32597138
复制相似问题