javascript - Message Passing from website to Chrome extension background script -
this question has answer here:
i trying communicate data website extension's content script should send background script store in extension's localstorage. have done far following : in webpage , script communicating extension's content script, 1 content script receives message logs in console 'message received'
my webpage :
<script> var go = function() { var event = document.createevent('event'); event.initevent('appid'); document.dispatchevent(event); } </script> <a href="javascript:go();">click me</a>
what want achieve simple make webpage send id cs passes background script ( since knowledge cs can not handle storing data in localstorage ). can 1 suggest necessary modification ?
in content script need send background by
var request={aaa:'bbb'};//object chrome.runtime.sendmessage(request);
and in background page, need
chrome.runtime.onmessage.addlistener(function(request, sender) { console.log(request); if(request.aaa) { console.log(request.aaa)//log:bbb //do sonething... } }
check doc further infos: https://developer.chrome.com/extensions/messaging
Comments
Post a Comment