我正在开发一个谷歌浏览器扩展。我的目的是将消息从我的 script1.js 发送到 script2.js。这是我在 manifest.json 中写的内容
{
"matches": ["https://www.google.fr/"],
"css": ["styles.css"],
"js": ["script1.js"]
},
{
"matches": ["my_website.html"],
"css": ["styles.css"],
"js": ["script2.js"]
},
Run Code Online (Sandbox Code Playgroud)
这是我在 script1.js 中写的:
chrome.runtime.sendMessage('你好世界!!!!!!');
在 script2.js 中:
chrome.runtime.onMessage.addListener(function(response,sender,sendResponse){
警报(响应);
});
我不认为我是用写的方式来做的,我想我必须使用 background.js 但我不知道如何。
首先十分感谢。