In this article, we will explore how to change the response body of JS files using an open-source developer tool called Requestly.
- Testing new functionality directly on the production site
- Testing bug fixes before shipping code
- Modifying JS content and testing for security-related things on the 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; you can access them here.
Let’s say you want to change the JS file used on Airbnb.com. In order to do that:
- Download and Install the Requestly desktop app.
- Open the app, and click Connect Apps.
- Choose the browser you want to launch.
- Search for airbnb.com and select the JS file you want to modify
- Right-click on the file and click Modify Response Body.
- Select HTML/CSS/JS in the pop-up and define the response body.
- Now save the rule by clicking Create Rule , and you will see the Airbnb website loading with your modified JS file.
- Go to requestly.io and install the browser extension from there
- Under Files, create a new JS file, and you will get a mock endpoint
- Go to Rules, and create a Redirect Rule.
- Replace the live JS file with the newly created mock endpoint
- Now the website will load the modified JS file every time it loads on your computer.
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.
Requestly is an Open-Source frontend development platform with essential tooling & integrations that helps frontend developers write, test & debug their code 10x faster. Using Requestly, you can create mock API endpoints, test, validate & override API responses, modify request & response headers, set up redirects (Map local, Map remote) and use Requestly sessions for faster debugging.
Originally published at https://requestly.io.