Documentation
¶
Overview ¶
Command intercept is a chromedp example demonstrating how to block, mock and change the requests of a page with the Fetch domain. It loads a local page that asks for an image, a script of an analytics service and two API endpoints. The program pauses these requests, and it answers each one in a different way. It fails the image and the analytics script with the reason BlockedByClient. It answers the first API request with a JSON body of its own, so the request never reaches the server. It adds a header to the second API request and lets the request continue. At the end, it prints the text that the page built from these answers and the number of requests that it blocked, mocked and continued. Every paused request must be continued, failed or fulfilled. A request that gets no answer waits forever, and the page stops. It starts a local server and needs no internet. Use -v to print the protocol messages, -visible to show the browser window and leave it open, and -visible-on-terminal to draw the page in the terminal with terminal graphics.