実現したいこと
chrome extension v3にて
background.js
→ content.js
にコンソールを表示させたい
発生している問題・エラーメッセージ
background.js:1 Uncaught (in promise) Error: Could not establish connection. Receiving end does not exist.
該当のソースコード
background.js
1chrome.tabs.query({active: true, lastFocusedWindow: true, currentWindow: true}, 2 function(tab) { 3 chrome.tabs.sendMessage(tab[0].id, {greeting: "hello"}) 4 } 5);
content.js
1chrome.runtime.onMessage.addListener(function(request, sender, sendResponse){ 2 console.log(request.greeting) 3})
manifest.json
1{ 2 "name": "テスト用", 3 "version": "1.0", 4 "manifest_version": 3, 5 "background": { 6 "service_worker": "background.js" 7 }, 8 "permissions": [ 9 "storage", 10 "activeTab", 11 "scripting", 12 "background", 13 "tabs" 14 ], 15 "content_scripts": [{ 16 "matches": ["<all_urls>"], 17 "js": ["content.js"] 18 }] 19}
試したこと
エラー文を検索し、以下のことを試してみましたが変化ありませんでした。
・chrome.runtime.onMessage.addListener()のfunctionの中の一番最後にreturn true
を記述
・更新ボタンを押す
・他の拡張機能が影響していないか、他の機能を全てOFF

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2022/07/25 14:58