browser.runtime.onMessage.addListener(function (message) { if (message.type === "MY_GET_URL_R") { window.postMessage(message); } else if (message.type === "GET_DATA_FROM_PAGE") { let company = document .querySelector('header[data-test="job-details-header"]') .children[0].children[0].querySelector("h4").innerHTML; let jobTitle = document .querySelector('header[data-test="job-details-header"]') .querySelector("h1").innerHTML; browser.runtime.sendMessage({ type: "GOT_INFO_R", company, jobTitle }); } else if (message.type === "GOT_INFO_R") { window.postMessage(message); } }); window.addEventListener("message", function (e) { if (e.data.type === "MY_GET_URL") { browser.runtime.sendMessage({ type: "MY_GET_URL" }); } else if (e.data.type === "HAS_EXTENSION_Q") { console.log("Got request for ext"); window.postMessage({ type: "HAS_EXTENSION" }); } else if (e.data.type === "REGISTER_INTEREST") { browser.runtime.sendMessage({ type: "REGISTER_INTEREST" }); } });