Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
fazdiu committed Nov 22, 2023
1 parent d33bacd commit 1254c0f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
14 changes: 14 additions & 0 deletions js/devtool.js
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");
}
);
34 changes: 34 additions & 0 deletions js/panel.js
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);
}

0 comments on commit 1254c0f

Please sign in to comment.