google chrome extension - Getting Port: Could not establish connection. Receiving end does not exist. and nothing has worked. Literally -
so, i've looked every other stack overflow post on topic, changed line line, , nothing working. (nevermind 99% of code straight off dev.google.com) no matter try, error mentioned in title. there doesn't seem explanation, i'm hoping group can spot potentially stupid thing i'm missing. thanks!
manifest.json
{ "manifest_version": 2, "name": "topic fetch", "description": "this extension extracts meta keywords news article , give related articles google news", "version": "1.0", "browser_action": { "default_icon": "icon.png", "default_title" : "get related links" }, "background": { "persistent": false, "scripts": ["background.js"] }, "content_scripts": [ { "matches": ["*://*/*"], "js": ["content-script.js"], "run_at": "document_end" } ], "permissions": [ "tabs","<all_urls>", "activetab" ] }
background.js
chrome.tabs.query({active: true, currentwindow: true}, function(tabs) { console.log(tabs); chrome.tabs.sendmessage(tabs[0].id, "message", function(response) { alert(response); }); });
content-script.js
chrome.runtime.onmessage.addlistener( function(message, sender, sendresponse) { sendresponse('hello!'); });
edit: here's code i'm using (for part) , info message passing in chrome extensions: https://developer.chrome.com/extensions/messaging.html
content script code won't run until refresh page, isn't listening yet. code in background.js not intended run (as have it). should run after have confirmed tab listening.
i suggest trying opposite way first: listen background.js , send message content script.
Comments
Post a Comment