0
我想从网站JavaScript发送数据到我的Chrome扩展。 我读了约sending msgs from website,我无法使它工作。将信息传递给网站的Chrome扩展
在我的网站:
$("#button-id").click(function(){
chrome.runtime.sendMessage("msg", {arg: "1"},
function(response){alert("got response: " + response);});
});
和background.js(Chrome扩展程序)
chrome.runtime.onMessageExternal.addListener(
function() {
alert("in background");
return "1";
});
我也加入到清单:
"externally_connectable": {
"matches": ["*://localhost/project/public/*","http://localhost/project/public/*","*://*/*/*"]
},
和所有我当我点击那个按钮时得到警报,说“得到的响应未定义”。
我试过的东西可能有助于弄清楚: 当我在我的网站上时,打开Chrome开发者控制台,输入“chrome.runtime.sendMessage(”jjj“);” 我正在'未定义'。
在此先感谢!