retrieve all active tabs content

jr_barros_jr
jr_barros_jr used Ask the Experts™
on
How can I retrieve all active tabs content (DOM) developing a Google Chrome Extension?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
To get the DOM for a specific tab, you would need to use content scripts communications.
https://developer.chrome.com/extensions/messaging

If you need to send a request from the extension to your content script,
chrome.tabs.getSelected(null, function(tab) {
  // Send a request to the content script.
  chrome.tabs.sendRequest(tab.id, {action: "getDOM"}, function(response) {
    console.log(response.dom);
  });
});

Open in new window


In the content script, if you need to listen for those events coming from the extension, use this code:
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
 if (request.action == "getDOM")
   sendResponse({dom: "The dom that you want to get"});
 else
   sendResponse({}); 
});

Open in new window

And look this article:
https://developer.chrome.com/extensions/extension#event-onRequest
And this article:
https://developer.chrome.com/extensions

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial