I'm trying to create a browser extension, specifically for Chrome. I copied the example almost exactly from here (https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/runtime/lastError) for a content and background script.
My content.js file
function send(e){
const sending = chrome.runtime.sendMessage({content:"message"})
console.log("THIS SHOULD BE A PROMISE",sending)
}
window.addEventListener("click",send)
My background.js file
function handleMessage(request, sender, sendResponse) {
console.log(`content received is: ${request.content}`);
return Promise.resolve({response: "response from background script"});
}
chrome.runtime.onMessage.addListener(handleMessage);
When I have the background page open, and I click, the background page prints content script sent a message: message
but my browswer's console prints THIS SHOULD BE A PROMISE undefined
.
My manifest.json file is minimal to replicate this.
{
"manifest_version": 2,
"name": "My First Extension",
"version": "0.1",
"browser_action": {
"default_icon": {
"16": "icon.png",
"24": "icon.png",
"32": "icon.png"
},
"default_title": "test"
},
"permissions": [
"activeTab",
"storage"
],
"background": {
"scripts": ["js/background.js"],
"persistent": false
},
"content_scripts": [
{
"matches": [ "http://*/*", "https://*/*", "file://*/*" ],
"js": [ "js/content.js" ]
}
],
Anyone have any idea what's going on? I checked multiple other threads on this topic to no avail.