javascript - Possible to modify cookie values in a jQuery ajax request? -


i working on chrome extension allow users record http requests site, modify pieces of request , resend it.

i'm hoping use jquery's ajax method construct , send modified request. have been able construct other parts of request, far can tell there no way include cookie values in request.

just clear - i'm not trying create cookie on browser, i'm trying modify cookie value sent along part of http request using jquery's ajax method.

can done jquery's ajax? if not, there anyway in javascript?

since you're talking chrome extension, can employ webrequest api intercept , modify requests.

chrome.webrequest.onbeforesendheaders.addlistener(   function(details) {     /* identify somehow it's request initiated */      (var = 0; < details.requestheaders.length; i++) {       if (details.requestheaders[i].name === 'cookie') {         /* */         break;       }     }      /* add cookie header if not found */      return {requestheaders: details.requestheaders};   },   {urls: ["*://*.example.com/*"]},    ["blocking", "requestheaders"] ); 

this way should able modify cookies without modifying browser's cookie store. i said "should" because have not tested solution.

some important points:

  • you need permissions: "webrequest", "webrequestblocking" , host permissions (for example, "*://*.example.com/")
  • there's caveat can't intercept own synchronous requests, precaution against deadlocks. long ajax asynchronous, should not matter.
  • if need prevent set-cookie response reaching cookie store, can modifying response headers in onheadersreceived. can use request id find corresponding response.

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -