クロムエクステンションをjsonバージョン2にアップデートしましたが、エクステンションを再度動作させようとしています。問題は、sendRequestが途中で減価償却されたことです。だから私はhttps://developer.chrome.com/extensions/messaging.htmlから私のスクリプトにコードをコピーし、自分の変数名に変更し、それは動作しません。Chrome拡張機能sendMessageエラーがコンテンツスクリプトからバックグラウンドへhtml
私は元のコードに戻って入れますが、それでも動作しません。私は似ている複数の質問を読んでいる[そしてうまくいけば、彼らのどれも私の状況と同じではなかったので、これは重複として閉じられないだろう]。
manifest.jsonを:
{
"background": {
"page": "background.html"
},
... ... ...
"content_scripts": [ {
"css": [ "style.css" ],
"js": [ "jq.js", "script.js" ],
"matches": [ "http://*.craigslist.org/*/*.htm*" ]
} ],
... ... ...
"permissions": [ "tabs", "http://*.craigslist.org/*/*.htm*" ],
"manifest_version": 2,
"update_url": "http://clients2.google.com/service/update2/crx",
"version": "3.0"
}
background.html:
<html>
<script type='text/javascript'>
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
console.log(sender.tab ?
"from a content script:" + sender.tab.url :
"from the extension");
if (request.greeting == "hello")
sendResponse({farewell: "goodbye"});
});
});
</script>
</html>
script.js:
chrome.runtime.sendMessage({greeting: "hello"}, function(response) {
console.log(response.farewell);
});
今RU (:27.0.1453.15(公式ビルド191758)ベータ版Google Chromeの):[Craigslistの上]ページのNA、およびコンソールに移動し、これは誤りである
Port error: Could not establish connection. Receiving end does not exist.
TypeError: Cannot read property 'farewell' of undefined
at chrome-extension://dhmjefbokfkjpdbigkadjpgjeflchgea/script.js:9:23
私はUbuntuの12.10、64ビットにクロームのベータ版を使用します
あなたは外部ファイルにインラインコードを移動する必要があります。この質問は以前に尋ねられており、詳細な回答が提供されています。 –
[マニフェストv1からv2へのクロム拡張を変更しているときにポートエラーが発生する可能性があります](http://stackoverflow.com/questions/11913575/port-error-while-changing-chrome-extension-from-manifest-v1-to- v2) –