Skip to content

Instantly share code, notes, and snippets.

@georgiyordanov
Created March 27, 2019 15:24
Show Gist options
  • Save georgiyordanov/24683c4c4ca27f8c1afbbcdf58c1d09f to your computer and use it in GitHub Desktop.
Save georgiyordanov/24683c4c4ca27f8c1afbbcdf58c1d09f to your computer and use it in GitHub Desktop.
Add custom headers to chrome
const chromeLauncher = require('chrome-launcher');
const CDP = require('chrome-remote-interface');
async function main() {
const chrome = await chromeLauncher.launch({
chromeFlags: [
'--window-size=1200,800',
`--user-data-dir=/tmp/chrome-data-dir`,
'--auto-open-devtools-for-tabs'
]
});
const protocol = await CDP({ port: chrome.port });
const { Runtime, Network } = protocol;
await Promise.all([ Runtime.enable(), Network.enable() ]);
Runtime.consoleAPICalled(({ args, type }) =>
console[type].apply(console, args.map(a => a.value)));
await Network.setCacheDisabled({cacheDisabled: true});
await Network.setExtraHTTPHeaders({ headers: { 'X-Forwarded-For': '10.10.55.40' } });
}
main().catch(e => {
console.error(e);
process.exit(1);
});
{
"name": "chrome-launch",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"chrome-launcher": "^0.10.5",
"chrome-remote-interface": "^0.27.1"
},
"devDependencies": {},
"scripts": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment