Trying to convert an extension from chrome to edge and I'm having an issue with browser.runtime.sendmessage() with a listener. To simplify things, I created a simple hello world extension. This new extension works in chrome but not edge. Anybody know what I need to change?
manifest.json
{
"manifest_version": 2,
"name": "My Cool Extension",
"author" : "Sandbox",
"version": "0.1",
"content_scripts": [ {
"all_frames": true,
"js": [ "jquery-3.1.1.min.js", "content_script.js" ],
"matches": [ "http://*/*", "https://*/*", "file://*/*" ]
} ],
"permissions": [ "http://*/*", "https://*/*", "storage" ],
"background": {
"scripts": [
"jquery-3.1.1.min.js",
"background.js"
],
"persistent": true
}
}
background.js
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
console.log(request.greeting);
if (request.greeting == "hello")
sendResponse({farewell: "goodbye"});
});
content_scripts.js
browser.runtime.sendMessage({greeting: "hello"}, function(response) {
if (response != undefined) {
console.log(response.farewell);
}
});
chrome.*
api while in Edge, you should usebrowser.*
api. - Haibara Ai