Is it possible to run a custom script whenever loading a web page on web browsers?

I would like to block content on some specific languages whenever I open a page on my browsers (Safari and Chrome on macOS 11.4). I think the best solution is to use Google Translate API and check which language the page is written in, and according to the result show the page as it is or an error message.

However, I'm not sure if it is possible to run a custom script whenever I open a web page on my browser. If it is possible, how can I do?


Yes, it possible to inject custom scripts when the page is opened. Many browser extensions are available for this like tampermonkey, violentmonkey, requestly. Using requestly extension you can run custom scripts based on the URL of the webpage.

Check them out:

  • tampermonkey
  • requestly, user script documentation
  • violentmonkey