Intercept & Modify Network Requests in Web Automation (Selenium, Playwright, etc.)

Requestly is a powerful browser extension that allows developers and QAs to intercept and modify HTTP requests. It offers features like:

  • HTTP header modifications

  • URL redirects

  • Request and response body overrides

  • Injecting custom CSS and JavaScript

In this guide, we’ll show you how to use Requestly in an end-to-end (E2E) web testing framework.

What You Can Do with Requestly in Automation For now

There are 2 main ways to use Requestly in an automation environment:

  1. Header Modifications — quick, one-off rules (no API key required)

  2. Import Rules via API Key — for predefined rules managed from your Requestly account

Header Modifications

If you only need simple header overrides (without API key), like adding or removing request/response headers, refer to this page:
Modify HTTP Headers →

Import Rules via API Key

1

Configure Rules in a Team Workspace and Get API Key

Start by creating the rules you want to use in a new team workspace. Once the rules are set up, request an API key for the workspace by filling out this form. The rules in this workspace will be automatically fetched and applied during the end-to-end (E2E) testing in the browser instance.

2

Install Chrome for Testing

Download Chrome for Testing, the automation-friendly version of Chrome.

Why Chrome for Testing?

Starting with Chrome 137, official Chrome builds no longer support the --load-extension flag due to security concerns. There commit →

To load extensions in automation tools (Selenium, Playwright, Puppeteer, etc.), you must use Chrome for Testing or Chromium.

Regular Chrome will block extension loading via automation. Use Chrome for Testing to avoid breakages and ensure compatibility.

3

Install the Automation Tool of Your Choice

npm install selenium-webdriver
4

Download the Requestly CRX Extension

Download the CRX file of the Requestly Extension.

5

Configure the Browser with the Extension

Use your automation tool’s configuration options to:

  • Set the path to Chrome for Testing binary

  • Add the Requestly CRX extension

For Javascript ( Node.js )

const { Builder } = require("selenium-webdriver");
const chrome = require("selenium-webdriver/chrome");
const path = require("path");

const options = new chrome.Options();
options.setChromeBinaryPath("/Path/to/chrome-for-testing"); 
options.addExtensions(path.resolve(__dirname, "requestly.crx"));  

const driver = await new Builder()
  .forBrowser("chrome")
  .setChromeOptions(options)
  .build();
// Now use driver.get() to navigate as needed...

For Python

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.binary_location = "/Path/to/chrome-for-testing"
chrome_options.add_extension("/path/to/requestly.crx")

driver = webdriver.Chrome(options=chrome_options)
# driver.get(...) to open pages

For Java

ChromeOptions options = new ChromeOptions();
options.setBinary("/Path/to/chrome-for-testing");
options.addExtensions(new File("/path/to/requestly.crx"));
WebDriver driver = new ChromeDriver(options);
// driver.get(...) to open pages
6

Import Rules from Requestly

Visit the following URL in your automated browser to import all active rules from your account:

https://app.requestly.io/automation?apiKey=<YOUR_API_KEY>

Updated on