XMLHttpRequest without cookies

How can I send a request from javascript that won't use cookies? I want to do this from greasemonkey, so it doesn't matter to me what the same origin is and can use both the original ones xmlhttprequest

and greamonkey GM_xmlhttpRequest .

I need to get a page from the same website, but not authorized. The browser (Firefox) always sends all the cookies that FF has for this domain.

Reference Information. I am working on a GM script that displays full sized versions of profile images. However, the only way to find out my url is I have to get the profile page for that user. This must be done non-automated, otherwise users will be notified of me by looking at their profile. Right now for development, I'm using php on my server to get the profile page, but that doesn't scale with distributing the GM script to other users.

+3


source to share


1 answer


You can set mozAnon or anonymous flag in the request parameters to suppress sending / storing cookies.

Unfortunately, these flags are not documented in the wiki , but they seem to be available since 3.8 beta3 (April 18, 2016).



GM_xmlhttpRequest({
   method: 'GET',
   url: url,
   anonymous: true, // remove original cookies
   headers: {
      cookie: 'whatever' // add custom cookies if necessary
   },
   onload: function(res) {
      // optionally parse the reponse cookies which are otherwise lost
      const cookieRegex = /^Set-Cookie: (.*)$/gm;
      const cookies = [];
      while (cookieRegex.exec(res.responseHeaders)) {
         cookies.push(RegExp.$1);
      }
      console.log(cookies);
   }
});

      

+1


source







All Articles