我試圖通過這裏發佈類似的問題進行瀏覽,但沒有一個似乎工作Chrome擴展端口錯誤:無法建立連接。接收端不存在
的manifest.json
{
"manifest_version": 2,
"name" : "A simple Found Text Demo",
"description" : "Bla",
"version" : "1.0",
"background" : {
"pages" : "background.html"
},
"page_action" : {
"default_icon" : "icon.png"
},
"content_scripts" : [{
"matches" : ["*://*/*"],
"js" : ["contentscript.js"]
}]
}
Background.html
<html>
<script>
chrome.extension.onMessage.addListener(
function(request, sender, sendResponse){
alert(request);
//chrome.pageAction.show(sender.tab.id);
sendResponse('Found!');
}
)
</script>
</html>
Contentscript.js
chrome.extension.sendMessage({"name" : "hola"}, function(res){
console.log(res); })
但是我重複得到相同的錯誤:
Port error: Could not establish connection. Receiving end does not exist.
任何想法?
這種情況在每次加載網頁上? – Ragnarokkr
是的,不要認爲這是重要的,我幾乎允許任何頁面調用此擴展(*:// */*) –
它很重要,因爲僞協議('chrome:','file:', 'view:'...)不允許注射,他們可能會產生類似你的錯誤。這就是我問它的原因。但是,@ RocketDonkey是正確的。清單版本2不允許內聯腳本。 – Ragnarokkr