I'm developing a Chrome extension where my content.js extracts data from a webpage and sends it to background.js using chrome.runtime.sendMessage. The data is correctly received and logged in background.js.
Now, I want to pass this data from background.js to popup.js and display it in my extension's popup HTML (popup.html). However, I'm encountering the error "Uncaught (in promise) Error: Could not establish connection. Receiving end does not exist" when trying to send the data from background.js to popup.js.
How can I effectively send the data from background.js to popup.js and display it in popup.html?
Manifest - Relevant Portion
"action": { "default_popup": "popup.html" },Content.JS
const name = document.querySelector('#name'); chrome.runtime.sendMessage(name);Background.JS
chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) { console.log(message); chrome.runtime.sendMessage(message);POPUP.JS
chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) { console.log("Message received in popup.js:", message);POPUP.HTML
<!DOCTYPE html>