Skip to main content

CDP / BiDi on Sauce Labs

The Chrome DevTools Protocol (CDP) support allows developers to debug web apps running on chromium browsers (such as Google Chrome or Microsoft Edge) by harnessing the power of "DevTools" functionality that is built in those browsers.

Sauce Labs offers you to use this feature using either the CDP API or BiDi (BiDirectional) API in combination with Selenium or Playwright as testing frameworks.

note

Selenium has stated in their reference that they will eventually move away from CDP, hence they suggest using the agnostic BiDi API, which abstracts away the implementation details of CDP.

What You’ll Need

  • A Sauce Labs account (Log in or sign up for a free trial license).
  • Your Sauce Labs Username.
  • A working development environment for one of the supported languages: Java, Python, or JavaScript (Node.js).

Enabling CDP / BiDi

In order to make use of the CDP / BiDi functionality, you have three possibilities:

1. Using Selenium

If you're using Selenium, you can enable CDP / BiDi by setting the devTools parameter in sauce:options to true.

options = ChromeOptions()
options.browser_version = 'latest'
options.platform_name = 'Windows 10'

sauce_options = {'username': os.environ["SAUCE_USERNAME"],
'accessKey': os.environ["SAUCE_ACCESS_KEY"],
'devTools': True,
'name': 'My Selenium CDP Test'}

options.set_capability('sauce:options', sauce_options)
sauce_url = "https://ondemand.us-west-1.saucelabs.com/wd/hub"
# Alternatively use EU datacenter
# sauce_url = "https://ondemand.eu-central-1.saucelabs.com/wd/hub"

driver = webdriver.Remote(command_executor=sauce_url, options=options)

2. Using Playwright (Selenium Grid)

Using Playwright in conjunction with Selenium Grid, you need to provide the Selenium Remote URL and the capabilities as environment variables:

SELENIUM_REMOTE_URL="https://{SAUCE_USERNAME}:{SAUCE_ACCESS_KEY}@ondemand.us-west-1.saucelabs.com:443/wd/hub"
SELENIUM_REMOTE_CAPABILITIES='{"browserName": "chrome", "sauce:options": {"devTools": "true", "name": "My Playwright Selenium Grid CDP Test"}}'

For more information, please refer to the Playwright Selenium Grid documentation

Limitations

  • CDP / BiDi Sessions are currently limited to 10mins
  • Extended debugging cannot be used along CDP / BiDi

Resources