forked from thingsinjars/devtools-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
49 lines (38 loc) · 1.53 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
// Chrome automatically creates a background.html page for this to execute.
// This can access the inspected page via executeScript
//
// Can use:
// chrome.tabs.*
// chrome.extension.*
chrome.extension.onConnect.addListener(function (port) {
var extensionListener = function (message, sender, sendResponse) {
if(message.tabId && message.content) {
//Evaluate script in inspectedPage
if(message.action === 'code') {
chrome.tabs.executeScript(message.tabId, {code: message.content});
//Attach script to inspectedPage
} else if(message.action === 'script') {
chrome.tabs.executeScript(message.tabId, {file: message.content});
//Pass message to inspectedPage
} else {
chrome.tabs.sendMessage(message.tabId, message, sendResponse);
}
// This accepts messages from the inspectedPage and
// sends them to the panel
} else {
port.postMessage(message);
}
sendResponse(message);
}
// Listens to messages sent from the panel
chrome.extension.onMessage.addListener(extensionListener);
port.onDisconnect.addListener(function(port) {
chrome.extension.onMessage.removeListener(extensionListener);
});
// port.onMessage.addListener(function (message) {
// port.postMessage(message);
// });
});
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
return true;
});