I am currently writing a userscript for website A
to access another the contents on website B
. So I tried to use the GM_xmlhttpRequest
to do it. However, a variable on B
is written to the window property eg: window.var
or responseContent.var
.
However, when I tried to get the window.var
, the output is undefined
, which means the properties under the window
variable cannot be read successfully. I guess the window object is refering to the website A
but not website B
, so the result is undefined (There is no window.var
on A
).
I am sure that the GM_xmlhttpRequest
has successfully read the content of the website B because I have added console.log
to see the response.responseText
. I have also used the window.var
to successfully visit that variable on website B by browser directly.
GM_xmlhttpRequest({
method: "GET",
url: url,
headers: {
referrer: "https://A.com"
},
onload: function (response) {
// console.log(response.responseText);
let responseContent = new Document();
responseContent = new DOMParser().parseFromString(response.responseText, "text/html");
let titleDiv = responseContent.querySelector("title");
if (titleDiv != null) {
if (titleDiv.innerText.includes("404")) {
console.log("404");
return;
} else {
console.log(responseContent.var);
console.log(window.var);
}
}
},
onerror: function (e) {
console.log(e);
}
});
I would like to retrieve content window.var on website B and show it on the console.log of A
Please help me solve the problem. Thank you in advance.