Skip to main content

Network Capture

warning

Network capture is currently available on WebOS, Tizen, and tvOS only. Additional platform support will be rolled out incrementally.

Overview

Network capture for HTTP traffic is available for Appium sessions. After a capture has completed an HTTP archive (HAR) file will be available for download by members of your organization via the TV Labs sessions dashboard.

Network capture can be started in two different ways described below.

Using Capabilities

Network capture can be enabled on session start by setting the tvlabs:log_network capability to true in the Appium session capabilities.

{
"tvlabs:constraints": "platform_key:web_os",
"tvlabs:build": "...",
"tvlabs:log_network": true
}

Using Execute Method

Network capture can be started or stopped in a middle of a session by using an Appium execute method. See more details on the Execute Methods page.

Viewing Network Logs

To download the HAR file for a session where network logging was enabled, navigate to the session in the TV Labs sessions dashboard. Scroll down and find the "Network Logs" section, and select the HTTP archives you wish to download.

Download network logs

note

Network logs may take a few moments to be available for download after the session ends.

There are many online tools available to view HAR files, but the easiest way is to import them into the Chrome DevTools. Open the DevTools within Chrome, select the "Network" tab, and look for the "Import HAR" button

Network logs in Chrome DevTools

Special Considerations for Roku

This section describes how to package your Roku BrightScript application with the TV Labs certificate. Due to limitations imposed by the Roku platform installing client certificates on the device is impossible, meaning to use network capture the TV Labs certificate must be embedded in the application package along with application logic when making network requests.

Downloading the Certificate

TV Labs provides an API endpoint to download the certificate bundle containing the TV Labs certificate. This example stores the certificate under certs/tvlabs-ca-bundle.pem in the application file tree.

curl -H "Authorization: Bearer $TVLABS_API_KEY" -o certs/tvlabs-ca-bundle.pem https://tvlabs.ai/api/v1/certificate/roku

Using the Certificate in Application Code

The ifHttpAgent interface provides a SetCertificatesFile method that can be used to set the certificate file used for HTTP requests made by the implementing object. Most Roku objects, including roSGNode and roUrlTransfer objects implement this interface, see the Roku documentation for more details.

Set the certificate file to the system default. This will be replaced with the TV Labs certificate in the next section:

req = CreateObject("roUrlTransfer")
req.SetCertificatesFile("common:/certs/ca-bundle.crt")
req.InitClientCertificates()
' ... make the request w/ certificate ...

Swapping the Certificate

The Perl script below can be used to replace all instances of the certificate path values in the application code.

# Find and replace all instances of the certificate path in `.brs` files in the current directory tree
find . -name "*.brs" -type f -exec perl -pi -e 's|common:/certs/ca-bundle.crt|pkg:/certs/tvlabs-ca-bundle.pem|g' {} +

After running the replacement script, the application code will look like this:

req = CreateObject("roUrlTransfer")
req.SetCertificatesFile("pkg:/certs/tvlabs-ca-bundle.pem")
req.InitClientCertificates()
' ... make the request w/ certificate ...

Package the application using your normal process, ensuring the TV Labs certificate is included in the certs directory. Your application package is now ready to be used with network interception!