I\'m trying to apply the following flow :
binding for keys in the background.js , when pressing them :
Sending message from background.js -> c
There are 3 ways to Send Message in Chrome Extension, you can refer to Message Passing.
Usually use one-time request, for example:
In background.js
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {message: "hello"}, function(response) {
console.log(response);
});
});
In contentscripts.js
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
console.log(request.message);
if (request.message == "hello") {
sendResponse({farewell: "goodbye"});
}
});