How to modify the response body of JS files

JS is the backbone of all modern web apps. Every website we interact with is powered with javascript. This is no surprise there are millions of javascript developers in the world. When building any web app, developers want to test the core functionality or a bug fix before the code is deployed to production. In any production app, script files are rendered by CDNs like Akamai, CloudFlare or AWS CloudFront. However, we have no control over these services, and hence modifying JS content and testing our code changes seem like a daunting task.

In this article, we will explore how to change the response body of JS files using an open-source developer tool called Requestly.

Use Cases

  1. Testing new functionality directly on the production site
  2. Testing bug fixes before shipping code
  3. Modifying JS content and testing for security-related things on the app

Modifying JS Response body using the Desktop app

Firstly, to change the response body it’s recommended to download Requestly’s desktop app, which has the capability to modify the live HTML/CSS/JS scripts. If you prefer a lightweight approach, you can use the Requestly browser extension. The steps are explained later in the blog.

Let’s say you want to change the JS file used on In order to do that:

  1. Download and Install the Requestly desktop app.
  2. Open the app, and click Connect Apps.
  3. Choose the browser you want to launch.
  4. Search for and select the JS file you want to modify
  5. Right-click on the file and click Modify Response Body.
  6. Select HTML/CSS/JS in the pop-up and define the response body.
  7. Now save the rule by clicking Create Rule, and you will see the Airbnb website loading with your modified JS file.
Click on the image to expand

Modifying JS file using Requestly browser extension:

If you wish to have a more lightweight approach, albeit not a straightforward one, you can install Requestly’s browser extension to modify the JS files of a website.

  1. Install the Requestly browser extension.
  2. Under Files, create a new JS file, and you will get a mock endpoint
  3. Go to Rules, and create a Redirect Rule.
  4. Replace the live JS file with the newly created mock endpoint
  5. Now the website will load the modified JS file every time it loads on your computer.

This article was written by:

Picture of Sagar Soni

Sagar Soni

Sagar is the co-founder and CTO of Requestly. When he's not busy architecting the next big thing in software development, you'll likely find him behind the wheel, cruising the streets and enjoying the thrill of the drive. For Sagar, it's all about the code by day and the open road by night.

Share this article:

You may also like