我知道它已经来过千百次了,但我现在被困住了。我已经阅读了大量答案并研究了 code.google.com 但没有成功。我正在尝试以 chrome 扩展名从background.html
to发送请求contentscript.js
。我设法让它以另一种方式工作。
里面的代码background.html
:
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.sendRequest(tab.id, {greeting: "hello"}, function(response) {
console.log(response.farewell);
});
});
里面的代码contentscript.js
:
chrome.extension.onRequest.addListener(
function(request, sender, sendResponse) {
if (request.greeting == "hello")
sendResponse({farewell: "goodbye"});
else
sendResponse({farewell: "nope"});
});
应该没问题,manifest.json
因为通信正在向后工作并且其他任何东西都可以正常工作。谢谢!