本文介绍了如何将选定的元素从devTools页面发送到chrome边栏页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发chrome devTools扩展程序.基本上,我在元素"面板中添加了一个侧边栏窗格. devtools.js

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>

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

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

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

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

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

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

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

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.

感谢您的帮助

推荐答案

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

这篇关于如何将选定的元素从devTools页面发送到chrome边栏页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 00:51