chrome插件通信方式

content_scripts里的js获取到页面的数据怎么发送到popup.js里?

content_scripts配置

"content_scripts": [{
    "matches": ["http://*/*", "https://*/*"],
    "js": ["static/index.js"]
}]

我在 index.js里

chrome.runtime.sendMessage('Hello', function(response) {
  console.log(response);
});

popup.js 里


chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
  console.log(11111)
});

完全没反应

阅读 2.5k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题