Complete the code to create a CDP session for network interception.
DevTools devTools = driver.[1]();The getDevTools() method is used to get the DevTools instance from the WebDriver.
Complete the code to enable the Network domain in CDP.
devTools.send(Network.[1]());The enable() command activates the Network domain to start intercepting network events.
Fix the error in the code to add a listener for network requests.
devTools.addListener(Network.[1], request -> { System.out.println("Request URL: " + request.getRequest().getUrl()); });
The correct event name is requestWillBeSent which fires before a network request is sent.
Fill both blanks to create a map of headers to modify a network request.
Map<String, Object> headers = new HashMap<>(); headers.put("[1]", "application/json"); headers.put("[2]", "no-cache");
The Content-Type header specifies the data format, and Cache-Control controls caching behavior.
Fill in the blanks to modify and continue a network request with new headers.
devTools.addListener(Network.requestIntercepted(), request -> {
Map<String, Object> headers = new HashMap<>(request.getRequest().getHeaders());
headers.put("[1]", "Bearer token123");
devTools.send(Network.[2](request.getInterceptionId(), headers));
});The Authorization header adds the token. The continueInterceptedRequest command continues the request with modified headers.