In this guide, we’ll walk through how to integrate Requestly into any browser-based automation framework (Selenium, Playwright, Puppeteer, etc.) to programmatically modify request and response headers.
Steps to Use Requestly for Header Modification in Automation
We also offer an NPM package, @requestly/rq-automation, to make this easier.
Learn more →
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.
Install the Automation Tool of Your Choice
npm install selenium-webdriver
Download the Requestly CRX Extension
If you're using our NPM package, you don’t need to download it. Simply call the function getExtension()
.
Download the CRX file of the Requestly Extension.
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, use our NPM package @requestly/rq-automation
.
Learn more →
For Javascript ( Node.js )
const { Builder } = require("selenium-webdriver");
const chrome = require("selenium-webdriver/chrome");
const path = require("path");
const extensionPath = path.resolve(__dirname, 'requestly.crx'); // unpacked CRX folder
// IF Using Our NPM Package @requestly/rq-automation
const { getExtension } = require("@requestly/rq-automation");
const extensionPath = getExtension("crx");
// -----
const options = new chrome.Options();
options.setChromeBinaryPath("/Path/to/chrome-for-testing");
options.addExtensions(extensionPath);
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
Close Extension Welcome Page
When Chrome installs the Requestly extension, it may open a "welcome" (post-install) tab that interrupts automation. You can close this tab programmatically:
// give Chrome a moment for any stray tabs
await driver.sleep(500);
// close any “welcome” tab if still present
const handles = await driver.getAllWindowHandles();
const mainHandle = handles[0];
for (const handle of handles.slice(1)) {
await driver.switchTo().window(handle);
await driver.close();
}
await driver.switchTo().window(mainHandle)
Perform Header Modifications Using Automation URLs
Once the browser is launched with Requestly, hit the following URLs to programmatically apply rules:
Add Request Header
To add multiple headers, simply append them using the &
symbol like this:
?header1=value1&header2=value2&header3=value3
https://app.requestly.io/automation/add-request-header?<headerName>=<headerValue>
Add Response Header
https://app.requestly.io/automation/add-response-header?<headerName>=<headerValue>
Remove Request Headers
To remove multiple headers, simply append them using the &
symbol like this:
?header1&header2&header3
https://app.requestly.io/automation/remove-request-header?<headerName>
Remove Response Headers
https://app.requestly.io/automation/remove-response-header?<headerName>
Test on a Live Site
To verify if the headers are successfully modified, open https://testheaders.com in the automated browser and inspect the headers shown.
You may need to trigger a button click to reveal headers on some pages.
Complete Working Example in Selenium ( Javascript )
Here’s a working example using Selenium, but this logic can be adapted easily to Playwright, Puppeteer, or others.
const { Builder, By, until } = require("selenium-webdriver");
const chrome = require("selenium-webdriver/chrome");
const path = require("path");
(async () => {
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();
// give Chrome a moment for any stray tabs
await driver.sleep(500);
// close any “welcome” tab if still present
const handles = await driver.getAllWindowHandles();
const mainHandle = handles[0];
for (const handle of handles.slice(1)) {
await driver.switchTo().window(handle);
await driver.close();
}
await driver.switchTo().window(mainHandle)
try {
await driver.get("https://app.requestly.io/automation/add-request-header?x-testing=selenium");
await driver.wait(
until.elementTextContains(
driver.findElement(By.tagName("body")),
"Success"
),
1000
);
await driver.get("https://testheaders.com");
await driver.findElement(By.css("button")).click();
await driver.wait(
until.elementTextContains(
driver.findElement(By.tagName("body")),
"x-testing"
),
5000
);
console.log("Header added and verified!");
} catch (err) {
console.error("Error during automation:", err);
} finally {
await driver.quit();
}
})();