问题
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