Skip to main content
Transform your testing process with: Real Device Features, Company-wide Licences, & App Percy
No Result Found

Header injection support on BrowserStack App Automate

Support for HTTP Headers is available only under Device Cloud Pro, Device Cloud Pro + Visual Cloud, and Enterprise Pro plans. For more details check out 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.

DesiredCapabilities capabilities = new DesiredCapabilities();
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\"}"
    }
}
AppiumOptions capabilities = new AppiumOptions();
Dictionary<string, object> browserstackOptions = new Dictionary<string, object>();
browserstackOptions.Add("headerParams", "{\"header_param_key1\":\"header_param_value1\", \"header_param_key2\":\"header_param_value2\"}");
capabilities.AddAdditionalCapability("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\"}"
}
AppiumOptions capability = new AppiumOptions();
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\"}"
}
desired_cap = {
    "browserstack.headerParams" => "{ \"header_param_key1\":\"header_param_value1\", \"header_param_key2\":\"header_param_value2\"}"
}
Note: Length of each key or value in headerParams or browserstack.headerParams must be less than 500 characters.

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 endpoints.
  • 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





Thank you for your valuable feedback

Is this page helping you?

Yes
No

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!

Talk to an Expert
Download Copy Check Circle