Inserting scripts dynamically in a webpage


Requestly brings you one of the most powerful tool which may prove to be replacement for many browser extensions. Using “Insert Scripts” rule, you can make on-the-fly changes to a webpage content.

If you love hacking, playing with automations, scraping, changing default website’s behaviour and have some basic knowledge of JavaScript, there’s a lot you can do here.

For example, remove/hide unwanted sections from page, add quick action buttons, add your own libraries to support your script, etc.

Every time the page is viewed, the specified script will be executed and changes will apply, thereby making the user experience seamless. Similar to any other rules in Requestly, Script rules too can be setup to execute on one or more web pages simultaneously

Here’s a quick demo on inserting scripts dynamically in a webpage.

How to create a Script rule using Requestly?

  • Install Requestly extension if you have not previously installed it.
  • Click on requestly icon in browser toolbar or Open
  • Click on Add (+) Icon to create a new Rule
  • Click on “Insert Scripts” card.

Enter rule name, description and webpage source where the rule has to be applied.

Select libraries (from available options) you want to include in webpage in order to support your custom scripts.

Click “Add Custom Script” button to add custom scripts which can be of two types:

  • URL– source of an external script
  • Code– JavaScript code snippet

Please note that Code script has a size limit. For longer code, one must create script file in Requestly File Library and copy URL to URL type custom script.

Each custom script has an option to be either included before page load or after page load. This provides user more flexibility to achieve multiple use-cases.

The extension ensures that firstly all libraries are inserted as custom scripts might depend on them. After libraries, all scripts meant to be loaded before page load are executed and then all scripts meant to be loaded after page load in the same order as they were added in rule builder.

For security reasons, rules created by a user remains private to him/her unless he deliberately shares with other users.

If you have any query or feedback, please feel free to reach out to [email protected]. We would love to respond to each of them.

Share this article:

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.