-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
34 lines (29 loc) · 1.09 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
// Chrome automatically creates a background.html page for this to execute.
// This can access the inspected page via executeScript
chrome.runtime.onConnect.addListener(function (port) {
var extensionListener = function (message, sender, sendResponse) {
if (message.tabId) {
//Evaluate script in inspectedPage
//Pass message to inspectedPage
// console.log("to current tab");
chrome.tabs.sendMessage(message.tabId, message, sendResponse);
} else {
// This accepts messages from the inspectedPage and
// sends them to the panel
// console.log("to panel");
port.postMessage(message);
}
sendResponse(message);
};
// Listens to messages sent from the panel
chrome.runtime.onMessage.addListener(extensionListener);
port.onDisconnect.addListener(function (port) {
chrome.runtime.onMessage.removeListener(extensionListener);
});
// port.onMessage.addListener(function (message) {
// port.postMessage(message);
// });
});
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
return true;
});