Google chrome 从chrome扩展访问DOM
我看了一下这个问题,但在启动时从chrome扩展访问当前选项卡的DOM时遇到了问题 我在chrome扩展的弹出页面中有这个Google chrome 从chrome扩展访问DOM,google-chrome,google-chrome-extension,Google Chrome,Google Chrome Extension,我看了一下这个问题,但在启动时从chrome扩展访问当前选项卡的DOM时遇到了问题 我在chrome扩展的弹出页面中有这个 $(document).ready(function() { chrome.tabs.getSelected(null, function(tab) { chrome.tabs.sendRequest(tab.id, { }, function(response) { console.log(response); }); }); 在我的内
$(document).ready(function() {
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.sendRequest(tab.id, { }, function(response) {
console.log(response);
});
});
在我的内容脚本中
chrome.extension.onRequest.addListener(
function(request, sender, sendResponse) {
sendResponse({ doc: document.body });
}
);
当我发回一个文本响应时,它可以工作,但是当我尝试发送document或document.body时,我在接收端没有得到任何信息。指定消息可以包含任何有效的JSON对象(null、boolean、number、string、array或object)
。在content\u脚本中使用dom操作代码,而不是尝试发送文档