Skip to content Skip to sidebar Skip to footer

Source Code Of Entire Page Including Frames In Chrome Extensions

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 URL gets the source cod

Solution 1:

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) + "...");
        });
    }
});

Post a Comment for "Source Code Of Entire Page Including Frames In Chrome Extensions"