-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Create a tab in the devtools area | ||
chrome.devtools.panels.create( | ||
"Extension 4.", | ||
null, | ||
"html/panel.html", | ||
(panel) => {} | ||
); | ||
|
||
chrome.devtools.panels.elements.createSidebarPane("Extension 4 Rules", | ||
function(sidebar) { | ||
sidebar.setPage("html/sidebar.html"); | ||
sidebar.setHeight("8ex"); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
document.getElementById("send").addEventListener("click", (e) => { | ||
console.log("click panel"); | ||
|
||
sendObjectToInspectedPage({ content: "message to content-script" }); | ||
}); | ||
|
||
/** | ||
* This creates and maintains the communication channel between the inspectedPage and the dev tools panel. | ||
*/ | ||
(function createChannel() { | ||
//Create a port with background page for continous message communication | ||
var port = chrome.runtime.connect({ | ||
name: "Sample Communication", //Given a Name | ||
}); | ||
|
||
// Listen to messages from the background page | ||
port.onMessage.addListener(function (message) { | ||
console.log("receive panel", message); | ||
}); | ||
})(); | ||
|
||
/** | ||
* This sends an object to the background page where it can be relayed to the inspected page | ||
* In this example, messages are JSON objects | ||
* { | ||
* content: [String|Object], data to be passed through | ||
* tabId: [Automatically added] | ||
* } | ||
* @param {Object} message | ||
*/ | ||
function sendToInspectedPage(message) { | ||
message.tabId = chrome.devtools.inspectedWindow.tabId; | ||
chrome.runtime.sendMessage(message); | ||
} |