Answer the question
In order to leave comments, you need to log in
How to pass messages from popup.js to content.js?
Good afternoon! I've been struggling for more than a day just to learn how to pass messages in an extension, I just can't catch up with how it works. How to send an event from popup js to content js? The essence is simple how to make it so that the image from the popup is placed on the active page of the browser in the first div element
Answer the question
In order to leave comments, you need to log in
To send a message from the popup window to the content script, you need to execute in the popup window:
chrome.tabs.query({}, function(tabs) {
for (i = 0; i < tabs.length; i++) {
chrome.tabs.sendMessage(tabs[i].id, 'Сообщение, которое нужно передать');
}
});
chrome.extension.onMessage.addListener(function(msg) {
console.log('Принято сообщение: ' + msg);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question