Skip to main content

Header injection support on BrowserStack Automate

Important: Support for HTTP Headers is currently in private Beta. Reach out to our Support team to try this feature.

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("headerParams", "{ "header_param_key1":"header_param_value1", "header_param_key2":"header_param_value2",}");
var capabilities = {
    "headerParams" : "{ "header_param_key1":"header_param_value1", "header_param_key2":"header_param_value2",}",
}
capability.AddAdditionalCapability("headerParams", "{ "header_param_key1":"header_param_value1", "header_param_key2":"header_param_value2",}");
desired_cap = {
    "headerParams" : "{ "header_param_key1":"header_param_value1", "header_param_key2":"header_param_value2",}",
}
caps = Selenium::WebDriver::Remote::Capabilities.new
caps["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.

The following image shows an HTTP header, Authorization, passed as part of the HTTP request in a test session. Custom HTTP Header in Browserstack Automate dashboard

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






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
Talk to an Expert