sending message to chrome extension from a web page
sending message to chrome extension from a web page I want to send message from the console of the random web page to my chrome extension. chrome.extension.sendMessage doesn't seem to work. 5 Answers 5 According to the official docs you should use postMessage in the sender and message event listener in the receiver. postMessage message Here is an example: Your website's page.html var data = { type: "FROM_PAGE", text: "Hello from the webpage!" }; window.postMessage(data, "*"); Content script: (injected using chrome.tabs.executeScript(tabid, {code:... ) chrome.tabs.executeScript(tabid, {code:... window.addEventListener("message", function(event) { // We only accept messages from ourselves if (event.source != window) return; if (event.data.type && (event.data.type == "FROM_PAGE")) { console.log("Conten...