In the Chrome extension I've created, sendMessage does not work and only port.postMessage works:
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
chrome.tabs.sendMessage(
tabs[0].id,
{ signal: "scrape" },
function (response) {
console.log(response.result);
}
);
});
port.postMessage also cannot send data to content.js:
const port2 = chrome.runtime.connect({ name: "background-script" });
port2.postMessage({ signal: "scrape" });
In this case, it works when sending from content.js to background.js or to another popup.js, but when sending to content.js, an error message appears saying that no end has occurred.
I'm not sure if it's a problem with Manifest V3 (it seems to have changed a lot). I've given permissions for tabs and activeTab.