Source code of entire page including frames in chrome extensions

前端 未结 1 1739
既然无缘
既然无缘 2021-01-16 19:29

The Question is in continuation to the link given below.

Getting the source HTML of the current page from chrome extension

The top answer given in the above

相关标签:
1条回答
  • 2021-01-16 19:47

    Use allFrames: true parameter of chrome.tabs.executeScript to inject the code into all frames. The callback function will receive an array with the results for all frames:

    popup.js:

    chrome.tabs.executeScript({
        allFrames: true,
        code: 'JSON.stringify({ \
                    url: location.href, \
                    html: document.documentElement.innerHTML \
               })'
    }, function(results) {
        if (chrome.runtime.lastError || !results || !results.length) {
            console.log("Some error occurred", chrome.runtime.lastError);
        } else {
            results.forEach(function(str, index) {
                var info = JSON.parse(str);
                console.log("Frame #%d | %s | %s", 
                    index, info.url, info.html.substr(0, 200) + "...");
            });
        }
    });
    
    0 讨论(0)
提交回复
热议问题