-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdevtools-background-connect.js
36 lines (30 loc) · 1.12 KB
/
devtools-background-connect.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
// Create a connection to the background page
var backgroundPageConnection = chrome.runtime.connect({
name: 'panel'
});
// we need to inject something that returns useful inspects because serialization
// between inspectedWindow and devtools is limited
var injectChromeEval = function() {
// load injected script
var xhr = new XMLHttpRequest();
xhr.open('GET', chrome.extension.getURL('/chrome-injection.js'), false);
xhr.send();
var script = xhr.responseText;
// inject into inspectedWindow
chrome.devtools.inspectedWindow.eval(script);
// chrome.devtools.inspectedWindow.getResources(function(stuff) {console.log(stuff);});
}
// connect to backgroundPage
backgroundPageConnection.postMessage({
name: 'init',
tabId: chrome.devtools.inspectedWindow.tabId
});
backgroundPageConnection.onMessage.addListener(function(msg) {
if(msg.eventType == "inject-opal-console-hooks") {
// run this everytime the page is refreshed
injectChromeEval();
}
// alert('backgroundPageConnection msg = ' + JSON.stringify(msg));
});
// run it the 1st time it's loaded
injectChromeEval();