Header injection support on BrowserStack Automate
Support for HTTP Headers is currently in private Beta. Public access to this feature will be exclusively available on the Automate Desktop & Mobile Pro Plan from July 1, 2024. Reach out to our Support team to try this feature. For more details, see our pricing page.
Use HTTP headers to pass additional context to your test session. BrowserStack supports both default HTTP headers along with custom headers that your organization might use.
In this guide, you will learn how to:
Pass HTTP header using capabilities
Use the headerParams
capability for W3C protocol and browserstack.headerParams
capability for JSON wire protocol in your test scripts to pass context. This capability accepts a JSON string with multiple, upto 5, key-value pairs as HTTP headers.
MutableCapabilities capabilities = new MutableCapabilities();
HashMap<String, Object> browserstackOptions = new HashMap<String, Object>();
browserstackOptions.put("headerParams", "{\"header_param_key1\":\"header_param_value1\", \"header_param_key2\":\"header_param_value2\"}");
capabilities.setCapability("bstack:options", browserstackOptions);
var capabilities = {
'bstack:options' : {
"headerParams" : "{\"header_param_key1\":\"header_param_value1\", \"header_param_key2\":\"header_param_value2\"}"
},
}
Dictionary<string, object> browserstackOptions = new Dictionary<string, object>();
browserstackOptions.Add("headerParams", "{\"header_param_key1\":\"header_param_value1\", \"header_param_key2\":\"header_param_value2\"}");
capabilities.AddAdditionalOption("bstack:options", browserstackOptions);
desired_cap = {
'bstack:options' : {
"headerParams" : "{\"header_param_key1\":\"header_param_value1\", \"header_param_key2\":\"header_param_value2\"}"
}
}
capabilities = {
'bstack:options' => {
"headerParams" => "{\"header_param_key1\":\"header_param_value1\", \"header_param_key2\":\"header_param_value2\"}"
}
}
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("browserstack.headerParams", "{\"header_param_key1\":\"header_param_value1\", \"header_param_key2\":\"header_param_value2\"}");
var capabilities = {
"browserstack.headerParams" : "{\"header_param_key1\":\"header_param_value1\", \"header_param_key2\":\"header_param_value2\"}"
}
capability.AddAdditionalCapability("browserstack.headerParams", "{\"header_param_key1\":\"header_param_value1\", \"header_param_key2\":\"header_param_value2\"}");
desired_cap = {
"browserstack.headerParams" : "{\"header_param_key1\":\"header_param_value1\", \"header_param_key2\":\"header_param_value2\"}"
}
caps = Selenium::WebDriver::Remote::Capabilities.new
caps["browserstack.headerParams"] = "{\"header_param_key1\":\"header_param_value1\", \"header_param_key2\":\"header_param_value2\"}"
Length of each key or value in headerParams
or browserstack.headerParams
must be less than 500 characters.
The following image shows an HTTP header, Authorization
, passed as part of the HTTP request in a test session.
Possible usage scenarios
You can use Default HTTP headers with custom headers for situations like:
- Support for third-party integration that requires passing authentication details to allow access to restricted sites.
- Pass additional context to identify different requests when using mocking servers.
- Pass custom headers, such as your BrowserStack Access Key, to applications, such as AWS Web Application Firewall to identify where a request originates from.
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
Thank you for your valuable feedback!