modify chromium source code is bad idea, for this task you can just create extension to modify request headers, and no need argument -disable-web-security
Create folder with name like headers_ext and add the following files
manifest.json
{
"manifest_version": 2,
"name": "Modify Request Headers",
"version": "1.0",
"permissions": [
"webRequest",
"webRequestBlocking",
"<all_urls>",
"tabs",
"webNavigation"
],
"background": {
"scripts": ["background.js"]
}
}
backround.js
function modifyRequestHeaders(request) {
for (var headers = request.requestHeaders, i = 0; i < headers.length; ++i) {
if (headers[i].name.toLowerCase() == 'accept') {
// set Cookie from 'Accept' header value
headers.push({"name" : "Cookie", "value" : headers[i].value});
// normalize 'Accept' header value
headers[i].value = '*/*';
}
}
return {requestHeaders: headers};
}
function modifyResponseHeaders(response) {
for (var headers = response.responseHeaders, i = 0; i < headers.length; ++i) {
if (headers[i].name.toLowerCase() == 'access-control-allow-origin') {
headers.splice(i, 1);
break;
}
}
// Allow cross domain
headers.push({"name": "Access-Control-Allow-Origin", "value": "*"});
return {responseHeaders: headers};
}
var webRequestOptions = {urls: ["<all_urls>"], types: ["xmlhttprequest"]};
chrome.webRequest.onBeforeSendHeaders.addListener(modifyRequestHeaders,
webRequestOptions, ["blocking", "requestHeaders", 'extraHeaders']);
chrome.webRequest.onHeadersReceived.addListener(modifyResponseHeaders,
webRequestOptions, ["blocking", "responseHeaders"]);
Now, in Chrome extension page click Load unpacked extension and locate the directory.
the extension above will only modify xmlhttprequest request headers and use Accept header value for Cookie value, It also modify response header to allow cross domain request by adding header Access-Control-Allow-Origin: *.
It seem for Chrome that DPR, Downlink, Save-Data, Viewport-Width, Width headers is not yet in safe-listed so I use Accept header instead to avoid OPTIONS or Preflight request, because many website doesn't support this. And extraHeaders is filter to allow modify or create Cookie.
For more CORS information read here
Make sure you're using latest Chrome and create request like this
$.ajax({
url: 'https://example.com',
type: 'POST', // or GET or HEAD
headers: {
// it will used for 'Cookie' value by extension
'Accept': "cookieName=cookieValue"
}
});