0
我正在構建一個Chrome擴展,當用戶單擊擴展圖標時會注入一些HTML和JS。所以,當單擊該圖標時,登記在BG腳本,內容腳本是收到了相關通知,像這樣:自定義newtab頁面:內容腳本將不會收到來自bgscript的消息
背景腳本
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頁面實際上收到該消息以及任何其他網頁。
我想,也許它是與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"
]
}
非常感謝您! – mufasa