Reputation: 41
I'm running a script in Tampermonkey, and I'm trying to use the GM_xmlhttpRequest method to send a POST request cross-domain. However It's not working for me. In the console I just get normal cross-origin the error:
XMLHttpRequest cannot load [domain1]. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin [domain2] is therefore not allowed access.
It's my understanding that the whole point of the GM request method is that it supports cross-domain unlike XMLHttpRequest(). So I'm not seeing why this will not work as it should. Here is the gist of what I'm doing:
// @match https://[domain2]
// @grant GM_xmlhttpRequest
GM_xmlhttpRequest({
method: "POST",
url: "https://[domain1]/exmaple.php",
data: formData,
onload: function(response) {}
console.log(response.responseText);
}
})
Maybe I'm missing something simple or I have the wrong idea
edit: I suppose I should note that the above code is nested inside a different normal XMLHttpRequest in case that would affect it.
Upvotes: 0
Views: 2311
Reputation: 41
Turns out that the "Unsafe window retrieval" setting in Tampermonkey just needed to be set to Native. Seems to be working now
Upvotes: 1