-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessaging.js
More file actions
26 lines (23 loc) · 924 Bytes
/
messaging.js
File metadata and controls
26 lines (23 loc) · 924 Bytes
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
// 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 continuous message communication
var port = chrome.extension.connect({
name: "Sample Communication" //Given a Name
});
// Listen to messages from the background page
port.onMessage.addListener(appendRecord)
};
// 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);
}