I have started working in a small proof of concept which is using PhantomJS to take screenshots and I'll get all the necessary configurations as system arguments such as URL, timeout, isScreenshotReqd, isHarFileReqd, isHeadersReqd, username, password and some application related configs. Everything is working fine except customHeaders
.
code I used is
if (system.args.length === 1) {
console.log('Usage: phantom.js <some URL>');
phantom.exit(1);
} else {
assembleId = system.args[2];
page.address = system.args[3];
page.settings.resourceTimeout = system.args[4];
isScreenshotReqd = system.args[5];
isHeadersReqd = system.args[6];
isHarFileReqd = system.args[7];
page.settings.userName = system.args[8];
page.settings.password = system.args[9];
var key = "headerKey";//(or system.args[10])
var value = "headerValue";//(or system.args[11])
page.customHeaders = {key : value};
//some operation
}
this sets the customHeader as
"headers": [{"name": "key","value": "headerValue"}]
You can see the value is set correctly but the key is not taken from initialized variable or system.args[x]
instead it takes whatever variable I use.
though it works if I hardcode the customHeaders like
page.customHeaders = {"headerKey": "headerValue"};
gives expected output but the problem is I'll be having dynamic headers for various URLs. It means it's config driven and each customer will give different headers for each URL.