-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbackground.js
53 lines (46 loc) · 1.64 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* existing to relay messages from content script to devtools */
var connections = {};
// Receive message from content script and relay to the devTools page for the
// current tab
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
/*
console.log('incoming message from injected script');
console.log(request);
console.log(sender);
*/
// Messages from content scripts should have sender.tab set
if(request.eventType == "inject-opal-console-hooks") {
// var result = chrome.tabs.executeScript(sender.tab.id, {file: 'chrome-injection.js'})
chrome.runtime.sendMessage({name: 'trying to initialize'});
window.postMessage( {name: 'window shit'}, "*");
console.log('injecting opal console hooks');
}
if (sender.tab) {
var tabId = sender.tab.id;
if (tabId in connections) {
connections[tabId].postMessage(request);
} else {
console.log("Tab not found in connection list.");
}
} else {
console.log("sender.tab not defined.");
}
return true;
});
chrome.runtime.onConnect.addListener(function(port) {
// Listen to messages sent from the DevTools page
port.onMessage.addListener(function(request) {
/*
console.log('incoming message from dev tools page');
console.log(request);
*/
// Register initial connection
if (request.name == 'init') {
connections[request.tabId] = port;
port.onDisconnect.addListener(function() {
delete connections[request.tabId];
});
return;
}
});
});