I have problem with accessing Facebook graph. I am using a Greasemonkey script. When I use the same script in chrome’s Tampermonkey it works well, and I can get data.
In Firefox nothing happens, I think maybe it’s because of cross-domain restrictions. Am I right, and is there a way this can be solved?
Forgot to mention, in Firefox only works if I am on graph.facebook.com.
edit:
var my_id = 1111111111;
var req = new XMLHttpRequest();
req.open('GET', 'https://graph.facebook.com/'+my_id, false);
req.send();
var contents = req.responseText;
alert(contents);
XMLHttpRequestdoes not support cross-domain requests. (You say this works in Tampermonkey though??!? Tampermonkey supportsGM_xmlhttpRequest()so it might have extended cross-domain XHR toXMLHttpRequest(), maybe.)Nevertheless, to get this to work in Greasemonkey (and Chrome userscripts, and Tampermonkey), you need to use
GM_xmlhttpRequest()— which allows cross domain requests.So the code from the question would become:
Note that
GM_xmlhttpRequest()operates asynchronously. (It has a somewhat dicey synchronous mode but that is not recommended.)