-
Notifications
You must be signed in to change notification settings - Fork 67
/
messaging.js
30 lines (26 loc) · 1.04 KB
/
messaging.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
// This creates and maintains the communication channel between
// the inspectedPage and the dev tools panel.
//
// In this example, messages are JSON objects
// {
// action: ['code'|'script'|'message'], // What action to perform on the inspected page
// content: [String|Path to script|Object], // data to be passed through
// tabId: [Automatically added]
// }
(function createChannel() {
//Create a port with background page for continous message communication
var port = chrome.extension.connect({
name: "Sample Communication" //Given a Name
});
// Listen to messages from the background page
port.onMessage.addListener(function (message) {
document.querySelector('#insertmessagebutton').innerHTML = message.content;
// port.postMessage(message);
});
}());
// This sends an object to the background page
// where it can be relayed to the inspected page
function sendObjectToInspectedPage(message) {
message.tabId = chrome.devtools.inspectedWindow.tabId;
chrome.extension.sendMessage(message);
}