Chrome extension: snap current tab to popup and then go through its DOM

I am doing a Google Chrome extension and have encountered a problem.

I am trying to download and search through the DOM inside popup.html.

This is how I get the current tab (I found the script somewhere, the loan does not belong to me):

 chrome.windows.getCurrent(function(w) {
      chrome.tabs.getSelected(w.id,function (response){
  )};

My problem is this: I need to go through the DOM of the response. When I tried to do this manually, I could not, because by default the response variable was undefined, so using the Console is not an option. When I try to notify the response in the html file, it appeared as an object. Then I tried to navigate the answer as if it were a "document" object, but no luck.

Any help would be greatly appreciated.

+3
2

, null getSelected.() script, :

chrome.extension.onRequest.addListener(
    function(request, sender, sendResponse) {
        if (request.action == "content")
        {
            console.log('content is ' + request.content.length + ' bytes');
        }
    });
chrome.tabs.getSelected(null, function(tab) {
        chrome.tabs.executeScript(tab.id, { file: 'scripts/SendContent.js' } );
    });

, , script... "scripts/SendContent.js" , script , , , executeScript:

    console.log('SendContent.js');
    chrome.extension.sendRequest( {
            action: "content",
            host: document.location.hostname,
            content: document.body.innerHTML
        }, function(response) { }
    );

:

POPUP: content is 67533 bytes

, console.log() , ( script ).

+4

, , , script DOM.

script chrome.tabs.executeScript, DOM script, , script, , API- .

, , .

+2

Source: https://habr.com/ru/post/1757060/


All Articles