如何将选中的元素从devTools页面发送到chrome侧边栏页面

How to I send selected element from devTools page to chrome sidebar page

本文关键字:侧边栏 chrome devTools 元素      更新时间:2023-09-26

我正在开发一个chrome devTools扩展。基本上我有一个侧边栏窗格添加到元素面板。 devtools.js

chrome.devtools.panels.elements.createSidebarPane("ChromeTrast", function(sidebar) {
  sidebar.setPage('devTools/chromeTrastDevTools.html');
}

chrometrastDevTools.html

<!DOCTYPE html>
<html>
<head lang="en">
  <meta charset="UTF-8">
</head>
<body>
  <p id="devTool-report"></p>
  <script src="../resources/jquery.js"></script>
  <script src="../resources/mustache.js"></script>
  <script src="../element/chromeTrastElement.js"></script>
  <script src="../element/RGB.js"></script>
  <script src="chromeTrastSidebar.js"></script>
</body>
</html>

在devtools.js中,我需要获得选定的元素($0)并将其发送到chrometrastSidebar.js。

基本上,我希望从devtools.js> chrometrastSidebar.js传递数据

chrometrastSidebar.js是来自侧边栏html页面的源文件。

我尝试使用chrome.devtools.inspectedWindow.eval(),但它没有工作。

我做了一些研究,但所有的消息从contentscript到背景页。

感谢您的帮助

You would preferably use to get and receive as below accordingly.
chrome.extension.sendMessage({greeting: "hello"}, function(response) {
  console.log(response.farewell);
});

chrome.extension.onMessage.addListener(
 function(request, sender, sendResponse) {
 if (request.greeting == "hello") sendResponse({farewell: JSON.stringify(sender)});
});