user1139452
user1139452

Reputation: 31

Accessing DOM from chrome extension

I took a look at this question but I'm having trouble with accessing the current tab's DOM from the chrome extension on startup,

Google Chrome Extension - Accessing The DOM

I have this in the popup page for the chrome extension,

$(document).ready(function() {
  chrome.tabs.getSelected(null, function(tab) {
    chrome.tabs.sendRequest(tab.id, { }, function(response) {
      console.log(response);
    });
});

and this in my content script,

chrome.extension.onRequest.addListener(
    function(request, sender, sendResponse) {
        sendResponse({ doc: document.body });    
    }
);

When I send a text response back it works, but when I try to send document or document.body, I don't get anything on the receiving end.

Upvotes: 0

Views: 1794

Answers (1)

abraham
abraham

Reputation: 47833

Message Passing specifies that a message can contain any valid JSON object (null, boolean, number, string, array, or object). Instead of trying to send the document have the dom manipulation code in the content_script.

Upvotes: 1

Related Questions