Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我希望在我的浏览器操作弹出窗口上运行一个脚本,以便在调用时从当前活动选项卡中获取信息。我不清楚如何在两者之间进行交流。我是否需要在活动选项卡上运行的内容脚本并chrome.tabs.sendMessage()从中请求信息?我应该申请什么权限?
chrome.tabs.sendMessage()
是的,内容脚本和其他脚本(背景、浏览器操作、页面操作)之间的通信是通过消息进行的。所以,在每一边你都有这样的代码:
chrome.runtime.onConnect.addListener(function(port) { port.onMessage.addListener(function(request) { // process the request // reply as port.postMessage(data) if needed }; };