javascript - Messaging between content script and popup script in Chrome extension -
i'm trying create popup chrome extension shows information dom in current page, seems require messaging. i've been able send messages background, need data specific current page, background identical popups/pages.
in popup.js
, send message when dom loaded (should trigger when popup clicked?)
document.addeventlistener('domcontentloaded', function() { chrome.runtime.sendmessage({method: "gettabledata"}, function response() { }); });
i have listener in contentscript.js
(and background.js
testing)
chrome.runtime.onmessage.addlistener(function(request, sender, sendresponse) { if(request.method == "gettabledata") { console.log("table request found!"); } });
then, when activate popup, background console outputs table request found!
, while console current page doesn't.
thanks.
you need use chrome.tabs.sendmessage
instead of chrome.runtime.sendmessage
send message content script.
Comments
Post a Comment