For Chrome or Edge, Selenium Java can add or replace headers on browser requests through the Chrome DevTools Protocol (CDP), using Network.setExtraHTTPHeaders. For a cross-browser approach, WebDriver BiDi defines network.setExtraHeaders, but the documented Selenium Java BiDi Network API does not currently list a direct helper for it. Choose the route based on the browser and the exact Selenium Java version you run.
This guide covers persistent extra headers on browser requests—not response headers, cookie APIs, or arbitrary per-request rewriting. The Selenium API details below reflect documentation current as of October 3, 2026; check the generated API for your pinned release before compiling.
Choose CDP or WebDriver BiDi
| Approach | When it fits | What to verify |
|---|---|---|
| Chrome DevTools Protocol (CDP) | Chrome or Edge tests that need to set extra request headers using Selenium Java. | Selenium documents a Java route using Network.setExtraHTTPHeaders. CDP is browser-specific and its API compatibility depends on browser versions. Pin and verify the Selenium/browser combination. Selenium CDP documentation |
| WebDriver BiDi | A standards-based, cross-browser direction when the browser and Selenium release support the needed command. | The W3C protocol defines network.setExtraHeaders, but Selenium’s documented Java BiDi Network module does not list a direct method by that name. Do not assume the command is exposed as a ready-to-use Java helper. Selenium BiDi guide · Selenium Java Network API |
Selenium describes CDP access as temporary while BiDi support is implemented. BiDi is the cross-browser direction, but command availability in the protocol specification and availability in a particular Selenium Java release are separate questions. Selenium’s CDP guidance
Set headers in Chrome or Edge with CDP
The following illustrates Selenium’s Java CDP approach. Selenium’s generated DevTools APIs are tied to protocol versions, so use the matching generated package and command for the Selenium version in your project. The imports below reflect Selenium’s documented CDP pattern; the exact versioned vNN package is intentionally project-specific.
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
import java.util.Map;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.devtools.DevTools;
import org.openqa.selenium.devtools.vNN.network.Network;
public class HeaderExample {
public static void main(String[] args) {
ChromeDriver driver = new ChromeDriver();
try {
DevTools devTools = driver.getDevTools();
devTools.createSession();
devTools.send(Network.enable(
java.util.Optional.empty(),
java.util.Optional.empty(),
java.util.Optional.empty()
));
devTools.send(Network.setExtraHTTPHeaders(
new org.openqa.selenium.devtools.vNN.network.model.Headers(
Map.of("X-Test-Header", "test-value")
)
));
driver.get("https://example.com/");
} finally {
driver.quit();
}
}
}
vNN is a replacement marker, not a literal Java package: select the generated CDP version present in your Selenium dependency and use its matching Network and Headers types. Selenium’s official CDP Network page provides the Java example and the command route: CDP Network documentation.
- Create a DevTools session from the Chrome driver.
- Enable the Network domain, then send
Network.setExtraHTTPHeaderswith a map of header names and values. - Navigate after setting the headers so the request is made with the configured extras.
- Verify the received header at a controlled server or test endpoint; do not infer success just because navigation completed.
The setting applies to requests from the browser session, rather than only to a single call to driver.get. If you need conditional logic for individual requests, use a supported interception feature instead of treating extra headers as a per-request callback.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
What BiDi specifies—and what Selenium Java exposes
The W3C WebDriver BiDi specification defines network.setExtraHeaders as a command that sets headers extending or overwriting existing request headers. If a header has the same name as an existing one, its value is overwritten rather than combined. The command accepts headers and optional browsing or user contexts. W3C WebDriver BiDi Working Draft, September 3, 2026
Selenium’s BiDi Java guide describes enabling a WebSocket connection with options.setCapability("webSocketUrl", true). However, the documented Java org.openqa.selenium.bidi.module.Network API is marked beta and lists methods such as interception and request continuation—not a direct setExtraHeaders method. Check your exact Selenium version and supported browser before writing code against that command; a protocol command in the W3C specification is not proof that Selenium’s Java wrapper exposes it.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
The specification also notes an ambiguity involving workers associated with multiple navigables. If your test depends on worker-originated requests, verify the behavior for the browser and implementation you actually use rather than assuming every worker inherits a single browsing context’s headers.
Header behavior and safe use
- Replacement, not append: BiDi’s specified behavior replaces an existing same-name value. Do not expect duplicate values to be merged.
- Request versus response: These commands affect outgoing request headers. They do not set response headers or replace cookie-management APIs.
- Persistent extras versus interception: Extra-header commands configure headers broadly for applicable requests. Per-request conditional rewriting is a separate network interception use case.
- Protect credentials: Keep authorization values in test configuration, do not place credentials in URLs, and avoid printing secret header values in logs.
- Validate at the receiver: Use a controlled endpoint that reports the request headers it received. This distinguishes a correctly configured browser request from a test that merely loaded a page.
Troubleshooting
The CDP imports or command do not compile
The generated CDP package version may not exist in the Selenium dependency you pinned, or the command signature may differ in that generated version. Inspect the Selenium artifacts and generated API for the installed release, then use its matching versioned Network and Headers classes. Avoid copying a package version from a different Selenium release.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
The request reaches the server without the header
Confirm that the DevTools session was created, the Network domain was enabled, and the extra headers were set before navigation. Then inspect the request at a controlled receiving endpoint. If the request originates from a worker or another context, check the browser’s behavior for that context.
The header value appears replaced or duplicated unexpectedly
For BiDi, same-name extra headers overwrite the existing value according to the specification. Choose a distinct header name if the test needs an additional field; do not rely on append behavior.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Clear out junk files and repair common Windows errors3Fix the driver behind crashes, sound loss and screen glitchesBest Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
The BiDi code shown online has no matching Java method
That may be a protocol-versus-binding mismatch. The documented Selenium Java Network module does not list a direct setExtraHeaders method. Check your exact release’s API and protocol support, or use the documented CDP route when testing Chrome or Edge is acceptable.
Or skip the browser setup
If your goal is a clean screenshot rather than testing arbitrary browser request headers, ScreenshotNeo takes a screenshot or PDF with one GET request. Its documented API is at ScreenshotNeo API docs.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
Cookie banners, popups and chat widgets are removed before capture; bot checks, blank pages and failed loads are not billed. An MCP server gives AI agents screenshot tools. The free plan includes 1,000 screenshots a month with no card, and paid plans start at $5 for 3,000 shots. Sign up free for 1,000 screenshots a month, no card required.
Frequently Asked Questions
Can Selenium WebDriver Classic set arbitrary request headers by itself?
No general WebDriver Classic command for rewriting browser network requests is established here. The documented routes are browser-specific CDP support or applicable BiDi protocol support.
Recommended Free Tools
Does WebDriver BiDi let me run a callback for every request?
No. The extra-header command sets extra headers; per-request interception is a distinct network feature.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

