Answer the question
In order to leave comments, you need to log in
How to properly notify content scripts about changes in browser extension settings?
There is an extension in which background.js is responsible for storing settings and processing data prepared by the content.js script. Everything works and seems to communicate with each other, but there were problems when writing a script for changing the extension settings.
What is the correct way to inform all tabs on which content.js functions that the settings have changed and that they need to be re-read?
Messages from background.js don't reach tabs.
I tried to send information to all tabs so that they re-read the settings.
chrome.tabs.query({active: false, currentWindow: false}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {command: "extEvSettingsUpdate"});
});
chrome.tabs.query({}, function(tabs) {
for (var i = 0; i < tabs.length; i++) {
chrome.tabs.sendMessage(tabs[i].id, {
command : "extEvSettingsUpdate"
});
}
});
Answer the question
In order to leave comments, you need to log in
//content.js
chrome.extension.onMessage.addListener(function(request, sender, callback){
if (!!request && !!request.command) {
if (request.command === "extEvSettingsUpdate") {
// your actions
}
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question