从Chrome扩展访问DOM

从Chrome扩展访问DOM

问题描述:

我看了看这个问题,但我在使用从启动Chrome扩展访问当前选项卡的DOM麻烦,从Chrome扩展访问DOM

Google Chrome Extension - Accessing The 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.body时,在接收端没有任何东西。

Message Passing指定a message can contain any valid JSON object (null, boolean, number, string, array, or object)。而不是试图发送文件有content_script中的dom操作代码。