Created
March 27, 2019 15:24
-
-
Save georgiyordanov/24683c4c4ca27f8c1afbbcdf58c1d09f to your computer and use it in GitHub Desktop.
Add custom headers to chrome
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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