Network logs
Network Logs capture performance data such as network traffic, latency, HTTP requests and responses in the HAR (HTTP Archive) format. You can leverage network logs to get a clear picture of all the network requests (e.g. REST API calls) originating from your app, and the time taken for each of these requests. It can help you identify performance bottenecks or debug failed REST API responses. You can visualize HAR files using the HAR Viewer.
Network logs are available on the BrowserStack dashboard for 30 days. These logs will be deleted after 30 days from the day they were generated.
Enable Network Logs
When you run a test without the Network log settings, the Network Logs tab on the dashboard shows the following message:
To enable Network logs, use the capability as shown below.
If you are using BrowserStack SDK, you can set the following capability within the browserstack.yml
file:
- Free trial users do not have access to the network logs feature for app testing. To subscribe to a paid plan, visit the pricing page.
- Network Logs feature is supported on all devices except the devices listed here under the Capabilities Reference section.
- Network Logs feature is not supported for proxy-unaware apps.
Network Log configurations
The following table provides information about the capability:
Capability | Configuration | Value |
---|---|---|
networkLogsOptions |
captureContent |
true , false Default: false (no content under Response tab) |
Use the following example code snippet to set the network log configurations:
Download network logs
The network logs can be viewed from the test sessions details page on the App Automate Dashboard. You can view or download network logs using the Raw Network Logs**.
Example network logs:
Import network logs using REST API
You can import the network logs from your test session using REST API:
curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" -X GET "https://api-cloud.browserstack.com/app-automate/builds/<build-id>/sessions/<session-id>/networklogs"
Handling certificate pinning issues
App developers may use certificate pinning techniques to prevent man-in-the-middle attacks and thus enhance the app’s security. Using certificate pinning, the app developer can associate (or “pin”) a remote host or service with its certificate or public keys at the time of development. When the app makes a network request to a remote host, it compares the pinned certificate with the remote server’s certificate to verify its identity.
However, on BrowserStack, if you have enabled network logs, your tests could fail if your app uses certificate pinning. This is because BrowserStack uses a MITM proxy to capture the network logs, causing network requests between the app and pinned hosts to fail.
BrowserStack provides you additional capabilities to fix certificate pinning errors. Using these capabilities, you can bypass BrowserStack’s MITM proxy while making requests to certificate-pinned remote hosts.
networkLogsExcludeHosts
For example, this will exclude capturing of logs for any requests made to api.example.com
and google.com
:
Capability | Description | Value |
---|---|---|
networkLogsExcludeHosts |
Use this capability to specify a list of certificate pinned hosts that should bypass BrowserStack MITM proxy while capturing network logs. By doing so, your tests can execute successfully while still capturing network logs for all other remaining hosts. | List of certificate pinned hosts (Array) or regex value (String) |
Only HTTPS URLs will be ignored for the specified hosts
networkLogsIncludeHosts
For example, this will capture logs only for network requests made to api.example.com
and google.com
Capability | Description | Value |
---|---|---|
networkLogsIncludeHosts |
Use this capability if you wish to capture network logs only for specific hosts. Traffic for all other remaining hosts will bypass BrowserStack MITM proxy and won’t be captured in network logs. | List of hosts (Array) or regex value (String) |
Both HTTP and HTTPS URLs will be captured for the specified hosts
BrowserStack SDK is a plug-n-play solution that takes care of all the integration steps for you. Using the BrowserStack SDK is the recommended integration method for your project. To know more, visit the SDK core concepts page.
Use the following code snippet to set the Network logs capability to true
:
Capability | Description | Value |
---|---|---|
networkLogs |
Capture network logs for your test |
true , false Default: false
|
Example :
DesiredCapabilities capabilities = new DesiredCapabilities();
HashMap<String, Object> browserstackOptions = new HashMap<String, Object>();
browserstackOptions.put("networkLogs", "true");
capabilities.setCapability("bstack:options", browserstackOptions);
var capabilities = {
'bstack:options' : {
"networkLogs" : "true",
},
}
AppiumOptions capabilities = new AppiumOptions();
Dictionary<string, object> browserstackOptions = new Dictionary<string, object>();
browserstackOptions.Add("networkLogs", "true");
capabilities.AddAdditionalCapability("bstack:options", browserstackOptions);
$caps = array(
'bstack:options' => array(
"networkLogs" => "true",
),
)
desired_cap = {
'bstack:options' : {
"networkLogs" : "true",
},
}
capabilities = {
'bstack:options' => {
"networkLogs" => "true",
},
}
After you set the networkLogs
capability to true, the Network Logs tab on the dashboard shows the following result:
Capability | Description | Value |
---|---|---|
browserstack.networkLogs |
Capture network logs for your test |
true , false Default: false
|
Example :
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("browserstack.networkLogs", "true");
var capabilities = {
'browserstack.networkLogs' : 'true',
}
AppiumOptions capabilities = new AppiumOptions();
capabilities.AddAdditionalCapability("browserstack.networkLogs", "true");
$caps = array(
"browserstack.networkLogs" => "true"
)
desired_cap = {
'browserstack.networkLogs' : 'true'
}
caps = Selenium::WebDriver::Remote::Capabilities.new
caps["browserstack.networkLogs"] = "true"
After you set the browserstack.networkLogs
capability to true, the Network Logs tab on the dashboard shows the following result:
- Free trial users do not have access to the network logs feature for app testing. To subscribe to a paid plan, visit the pricing page.
- Network Logs feature is supported on all devices except the devices listed here under the Capabilities Reference section.
- Network Logs feature is not supported for proxy-unaware apps.
Network Log configurations
The following table provides information about the capability:
Capability | Configuration | Value |
---|---|---|
browserstack.networkLogsOptions |
captureContent |
true, false Default: false (no content under Response tab) |
Use the following example code snippet to set the network log configurations:
DesiredCapabilities capabilities = new DesiredCapabilities();
networkLogsOptions.put("captureContent", true);
capabilities.setCapability("browserstack.networkLogs", true);
capabilities.setCapability("browserstack.networkLogsOptions", networkLogsOptions);
var capabilities = {
"browserstack.networkLogs" : "true",
"browserstack.networkLogsOptions": {
"captureContent": "true"
}
}
AppiumOptions capabilities = new AppiumOptions();
networkLogsOptions.Add("captureContent", "true");
capabilities.AddAdditionalCapability("browserstack.networkLogs", "true");
capabilities.AddAdditionalCapability("browserstack.networkLogsOptions", networkLogsOptions);
$caps = array(
"browserstack.networkLogs" => "true",
"browserstack.networkLogsOptions" => array (
"captureContent" => "true"
)
);
desired_cap = {
"browserstack.networkLogs" : "true",
"browserstack.networkLogsOptions": {
"captureContent": "true"
}
}
Download network logs
The network logs can be viewed from the test sessions details page on the App Automate Dashboard. You can view or download network logs using the Raw Network Logs**.
Example network logs:
Import network logs using REST API
You can import the network logs from your test session using REST API:
curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" -X GET "https://api-cloud.browserstack.com/app-automate/builds/<build-id>/sessions/<session-id>/networklogs"
Handling certificate pinning issues
App developers may use certificate pinning techniques to prevent man-in-the-middle attacks and thus enhance the app’s security. Using certificate pinning, the app developer can associate (or “pin”) a remote host or service with its certificate or public keys at the time of development. When the app makes a network request to a remote host, it compares the pinned certificate with the remote server’s certificate to verify its identity.
However, on BrowserStack, if you have enabled network logs, your tests could fail if your app uses certificate pinning. This is because BrowserStack uses a MITM proxy to capture the network logs, causing network requests between the app and pinned hosts to fail.
BrowserStack provides you additional capabilities to fix certificate pinning errors. Using these capabilities, you can bypass BrowserStack’s MITM proxy while making requests to certificate-pinned remote hosts.
browserstack.networkLogsExcludeHosts
Capability | Description | Value |
---|---|---|
networkLogsExcludeHosts |
Use this capability to specify a list of certificate pinned hosts that should bypass BrowserStack MITM proxy while capturing network logs. By doing so, your tests can execute successfully while still capturing network logs for all other remaining hosts. | List of certificate pinned hosts (Array) or regex value (String) |
For example, this will exclude capturing of logs for any requests made to api.example.com
and google.com
:
Example :
DesiredCapabilities capabilities = new DesiredCapabilities();
HashMap<String, Object> browserstackOptions = new HashMap<String, Object>();
browserstackOptions.put("networkLogsExcludeHosts", new String[]{"api.example.com", "google.com"});
capabilities.setCapability("bstack:options", browserstackOptions);
var capabilities = {
'bstack:options' : {
'networkLogsExcludeHosts': ['api.example.com', 'google.com'],
}
}
AppiumOptions capabilities = new AppiumOptions();
Dictionary<string, object> browserstackOptions = new Dictionary<string, object>();
browserstackOptions.Add("networkLogsExcludeHosts", new[] {'api.example.com', 'google.com'});
capabilities.AddAdditionalCapability("bstack:options", browserstackOptions);
$caps = array(
'bstack:options' => array(
"networkLogsExcludeHosts" => ["api.example.com", "google.com"],
),
)
desired_cap = {
'bstack:options' : {
'networkLogsExcludeHosts': ['api.example.com', 'google.com']
}
}
capabilities = {
'bstack:options' => {
'networkLogsExcludeHosts': ['api.example.com', 'google.com']
}
}
Instead of using an array, you can also pass a regex value as a string to dynamically match a list of hosts. For example, this will exclude capturing of logs for any requests made to example.com
and its subdomains.
DesiredCapabilities capabilities = new DesiredCapabilities();
HashMap<String, Object> browserstackOptions = new HashMap<String, Object>();
browserstackOptions.put("networkLogsExcludeHosts", "^(.+\.)?example.com");
capabilities.setCapability("bstack:options", browserstackOptions);
var capabilities = {
'bstack:options' : {
'networkLogsExcludeHosts': '^(.+\.)?example.com',
}
}
AppiumOptions capabilities = new AppiumOptions();
Dictionary<string, object> browserstackOptions = new Dictionary<string, object>();
browserstackOptions.Add("networkLogsExcludeHosts", "^(.+\.)?example.com");
capabilities.AddAdditionalCapability("bstack:options", browserstackOptions);
$caps = array(
'bstack:options' => array(
"networkLogsExcludeHosts" => "^(.+\.)?example.com",
),
)
desired_cap = {
'bstack:options' : {
'networkLogsExcludeHosts': '^(.+\.)?example.com'
}
}
capabilities = {
'bstack:options' => {
'networkLogsExcludeHosts': '^(.+\.)?example.com'
}
}
Capability | Description | Value |
---|---|---|
browserstack.networkLogsExcludeHosts |
Use this capability to specify a list of certificate pinned hosts that should bypass BrowserStack MITM proxy while capturing network logs. By doing so, your tests can execute successfully while still capturing network logs for all other remaining hosts. | List of certificate pinned hosts (Array) or regex value (String) |
For example, this will exclude capturing of logs for any requests made to api.example.com
and google.com
:
Example :
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability("browserstack.networkLogsExcludeHosts", new String[]{"api.example.com", "google.com"});
var capabilities = {
'browserstack.networkLogsExcludeHosts': ['api.example.com', 'google.com'],
}
DesiredCapabilities capability = new DesiredCapabilities();
capability.SetCapability("browserstack.networkLogsExcludeHosts", new[] {'api.example.com', 'google.com'});
$capabilities = new DesiredCapabilities();
$capabilities->setCapability("browserstack.networkLogsExcludeHosts", ["api.example.com", "google.com"]);
desired_cap = {
'browserstack.networkLogsExcludeHosts': ['api.example.com', 'google.com']
}
desired_caps = {
'browserstack.networkLogsExcludeHosts': ['api.example.com', 'google.com']
}
Instead of using an array, you can also pass a regex value as a string to dynamically match a list of hosts. For example, this will exclude capturing of logs for any requests made to example.com
and its subdomains.
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability("browserstack.networkLogsExcludeHosts", "^(.+\.)?example.com");
var capabilities = {
'browserstack.networkLogsExcludeHosts': '^(.+\.)?example.com',
}
DesiredCapabilities capability = new DesiredCapabilities();
capability.SetCapability("browserstack.networkLogsExcludeHosts", "^(.+\.)?example.com");
$capabilities = new DesiredCapabilities();
$capabilities->setCapability("browserstack.networkLogsExcludeHosts", "^(.+\.)?example.com");
desired_cap = {
'browserstack.networkLogsExcludeHosts': '^(.+\.)?example.com'
}
desired_caps = {
'browserstack.networkLogsExcludeHosts': '^(.+\.)?example.com'
}
Only HTTPS URLs will be ignored for the specified hosts
networkLogsIncludeHosts
Capability | Description | Value |
---|---|---|
networkLogsIncludeHosts |
Use this capability if you wish to capture network logs only for specific hosts. Traffic for all other remaining hosts will bypass BrowserStack MITM proxy and won’t be captured in network logs. | List of hosts (Array) or regex value (String) |
For example, this will capture logs only for network requests made to api.example.com
and google.com
DesiredCapabilities capabilities = new DesiredCapabilities();
HashMap<String, Object> browserstackOptions = new HashMap<String, Object>();
browserstackOptions.put("networkLogsIncludeHosts", new String[]{"api.example.com", "google.com"});
capabilities.setCapability("bstack:options", browserstackOptions);
var capabilities = {
'bstack:options' : {
'networkLogsIncludeHosts': ['api.example.com', 'google.com'],
}
}
AppiumOptions capabilities = new AppiumOptions();
Dictionary<string, object> browserstackOptions = new Dictionary<string, object>();
browserstackOptions.Add("networkLogsIncludeHosts", new[] {'api.example.com', 'google.com'});
capabilities.AddAdditionalCapability("bstack:options", browserstackOptions);
$caps = array(
'bstack:options' => array(
"networkLogsIncludeHosts" => ["api.example.com", "google.com"],
),
)
desired_cap = {
'bstack:options' : {
'networkLogsIncludeHosts': ['api.example.com', 'google.com']
}
}
desired_caps = {
'bstack:options' => {
'networkLogsIncludeHosts': ['api.example.com', 'google.com']
}
}
Instead of using an array, you can also pass a regex value as a string to dynamically match a list of hosts. For example, this will capture logs for any network requests made to example.com
and its subdomains.
DesiredCapabilities capabilities = new DesiredCapabilities();
HashMap<String, Object> browserstackOptions = new HashMap<String, Object>();
browserstackOptions.put("networkLogsIncludeHosts", "^(.+\.)?example.com");
capabilities.setCapability("bstack:options", browserstackOptions);
var capabilities = {
'bstack:options' : {
'networkLogsIncludeHosts': '^(.+\.)?example.com',
}
}
AppiumOptions capabilities = new AppiumOptions();
Dictionary<string, object> browserstackOptions = new Dictionary<string, object>();
browserstackOptions.Add("networkLogsIncludeHosts", "^(.+\.)?example.com");
capabilities.AddAdditionalCapability("bstack:options", browserstackOptions);
$caps = array(
'bstack:options' => array(
"networkLogsIncludeHosts" => "^(.+\.)?example.com",
),
)
desired_cap = {
'bstack:options' : {
'networkLogsIncludeHosts': '^(.+\.)?example.com'
}
}
desired_caps = {
'bstack:options' => {
'networkLogsIncludeHosts': '^(.+\.)?example.com'
}
}
Capability | Description | Value |
---|---|---|
browserstack.networkLogsIncludeHosts |
Use this capability if you wish to capture network logs only for specific hosts. Traffic for all other remaining hosts will bypass BrowserStack MITM proxy and won’t be captured in network logs. | List of hosts (Array) or regex value (String) |
For example, this will capture logs only for network requests made to api.example.com
and google.com
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability("browserstack.networkLogsIncludeHosts", new String[]{"api.example.com", "google.com"});
var capabilities = {
'browserstack.networkLogsIncludeHosts': ['api.example.com', 'google.com'],
}
DesiredCapabilities capability = new DesiredCapabilities();
capability.SetCapability("browserstack.networkLogsIncludeHosts", new[] {'api.example.com', 'google.com'});
$capabilities = new DesiredCapabilities();
$capabilities->setCapability("browserstack.networkLogsIncludeHosts", ["api.example.com", "google.com"]);
desired_cap = {
'browserstack.networkLogsIncludeHosts': ['api.example.com', 'google.com']
}
desired_caps = {
'browserstack.networkLogsIncludeHosts': ['api.example.com', 'google.com']
}
Instead of using an array, you can also pass a regex value as a string to dynamically match a list of hosts. For example, this will capture logs for any network requests made to example.com
and its subdomains.
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability("browserstack.networkLogsIncludeHosts", "^(.+\.)?example.com");
var capabilities = {
'browserstack.networkLogsIncludeHosts': '^(.+\.)?example.com',
}
DesiredCapabilities capability = new DesiredCapabilities();
capability.SetCapability("browserstack.networkLogsIncludeHosts", "^(.+\.)?example.com");
$capabilities = new DesiredCapabilities();
$capabilities->setCapability("browserstack.networkLogsIncludeHosts", "^(.+\.)?example.com");
desired_cap = {
'browserstack.networkLogsIncludeHosts': '^(.+\.)?example.com'
}
desired_caps = {
'browserstack.networkLogsIncludeHosts': '^(.+\.)?example.com'
}
Both HTTP and HTTPS URLs will be captured for the specified hosts
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!