chrome.extension.onConnect.addListener(function(port) {
console.log("Connected .....");
port.onMessage.addListener(function(msg) {
try{
port.postMessage('active_port');
} catch {
port.postMessage('disable_port');
}
});
})
setInterval(() => {
try {
var port = chrome.extension.connect({
name: "Sample Communication"
});
port.postMessage("active back");
port.onMessage.addListener(function(msg) {
console.log(msg);
});
} catch {
localStorage.setItem('reload_' + appId, 1);
location.reload();
}
}, 5000);
chrome.extension.sendMessage('Ваше сообщение');
chrome.extension.onMessage.addListener(function(message) {
console.log('Принято сообщение: ' + message);
});