-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
24 lines (23 loc) · 1.01 KB
/
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
//This is the background code
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() {
var i = ports.indexOf(port);
if (i !== -1) ports.splice(i, 1);
});
chrome.windows.getCurrent(function(win){
chrome.tabs.getAllInWindow(win.id, function(tabs) {
tabs.forEach(function(tab) {
//Post tab info to port only if the page is viddigo or mraid.
if(tab.active && tab.selected && tab.highlighted && (tab.status === "complete") && ((tab.title === "Viddigo") || (tab.title === "Device Simulator"))) {
ports.forEach(function(port) {
port.postMessage(tab);
});
}
});
});
});
});