-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
26 lines (23 loc) · 738 Bytes
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
var ports = [];
chrome.runtime.onConnect.addListener(function(port) {
if (port.name !== 'devtools') return;
ports.push(port);
// Remove port when destroyed (eg when devtools instance is closed)
port.onDisconnect.addListener(function() {
console.log('Port disconnected!');
var i = ports.indexOf(port);
if (i !== -1) ports.splice(i, 1);
});
port.onMessage.addListener(function(msg) {
// console.log('Received message from devtools port', msg);
});
});
// Function to send a message to all devtools.html views:
function notifyDevtools(msg) {
ports.forEach(function(port) {
port.postMessage(msg);
});
}
chrome.storage.onChanged.addListener(function(changes, areaName) {
notifyDevtools(changes);
});