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

…衆ロ難τιáo~ 提交于 2021-02-07 18:20:25

问题


I'm working on a chrome devTools extension. Basically I have a sidebar pane added to the Element panel. 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>

Within devtools.js, I need to get the selected element ($0) and send it to chrometrastSidebar.js.

basically, I am looking to pass data from devtools.js > chrometrastSidebar.js

chrometrastSidebar.js is a source file from the html page of the sidebar.

I tried using chrome.devtools.inspectedWindow.eval() but it didn't work.

I did some research but all are messaging from contentscript to bacground page.

thanks for any help


回答1:


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)});
});


来源:https://stackoverflow.com/questions/25128330/how-to-i-send-selected-element-from-devtools-page-to-chrome-sidebar-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!