Let's say for example I want to get the <head> tag of youtube or another remote website. Currently, I get an error that states:
Access to XMLHttpRequest at ‘WebSite I request to get the head section’ from origin ‘My Website’ has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
I have tried doing an XMLHttpRequest but I'm blocked by the origin. In this case, I'm not trying to inject or modify something but instead get the head section which you can easily get by copy-pasting from the source code (so I don't see a security concern there).
This is the function I'm using to make that happen:
function httpGet(theUrl) {
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
console.log(xmlhttp.responseText);
return xmlhttp.responseText;
}
}
xmlhttp.open("GET", theUrl, false);
xmlhttp.send();
}
Is there a way to possibly send a request to a remote site and get the head content (read-only)? Currently, there are similar questions here but none of them answer as different things worked for different developers and I have a hard time understanding if that is a possibility.
Update: here is the manifest.json file however, i want to mention again that the user doesn't have that domain open in a tab or anywhere else. It's just a random domain.
{
"manifest_version": 3,
"version": "0.0.5",
"action": {
"default_popup": "popup/popup.html"
},
"permissions": ["activeTab", "scripting"],
"host_permissions": ["<all_urls>"]
}