/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// contentscript.js - get inserted into the browser page chrome.extension.sendRequest({greeting: "hello"}, function(response) { console.log(response.farewell); }); // background.html - opens a listener to listen for requests chrome.extension.onRequest.addListener( function(request, sender, sendResponse) { console.log(sender.tab ? "from a content script:" + sender.tab.url : "from the extension"); if (request.greeting == "hello") sendResponse({farewell: "goodbye"}); else sendResponse({}); // snub them. });