When developing a Chrome Extension, how do you access to the source code for the current tab?
The current solution I have implemented is doing a request, so I get the source code from the request object. But as I do this, I need to give permission to every site in the manifest.json file. I don't want to use wildcards to give permission to all pages, but I don't want to add only specific URLs, so I would like to find a more straight-forward solution that doesn't include the fact of making a request.
The current solution below:
function getSourceCode(url) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
var parser = new DOMParser();
source_code = parser.parseFromString(xhr.responseText, "text/html");
// handle source code ...
}
};
xhr.send();
}
Thanks!