Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google chrome 从chrome扩展访问DOM_Google Chrome_Google Chrome Extension - Fatal编程技术网

Google chrome 从chrome扩展访问DOM

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); }); }); 在我的内

我看了一下这个问题,但在启动时从chrome扩展访问当前选项卡的DOM时遇到了问题

我在chrome扩展的弹出页面中有这个

$(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操作代码,而不是尝试发送文档