I am looking for a Firefox addon or Chrome extension that would allow me to disable particular javascript file from running. There are many of those for disabling particular CSS file, cannot seem to find one that does the same with JS files. Is there some limitations or I should have searched better before posting?
3 Answers
This can be done quite easily via a Chrome extension, using the webRequest
API. The example below blocks all external scripts. Replace <all_urls>
with a more specific pattern. For very dynamic patterns, you can modify the chrome.webRequest.onBeforeRequest
event listener.
- Create a new directory.
- Create the files below.
- Load the unpacked extension in Developer mode via
chrome://extensions/
background.js
chrome.webRequest.onBeforeRequest.addListener(
function() { return {cancel: true}; },
{
urls: ["<all_urls>"], // Change this to a more specific pattern
types: ["script"]
},
["blocking"]
);
manifest.json
{
"name": "Block request",
"version": "1.0",
"manifest_version": 2,
"background": {
"scripts": ["background.js"]
},
"permissions": [
"webRequest",
"webRequestBlocking",
"<all_urls>"
]
}
PS. Keep an eye on the chrome.declarativeWebRequest
API. At the time of writing, it's in the beta/dev channel, but when you read this answer. This new API is more efficient than the webRequest
API, and allows one to use event pages instead of background pages (the webRequest
API cannot be used on event pages).

- 341,306
- 83
- 791
- 678
-
1Works in 2017 (chrome 58.0.3029.81) – Marcin Robaszyński Apr 21 '17 at 23:30
-
Worked for me too 2017 (chrome 61.0.3163.100). Dev tools console shows "Failed to load resource: net::ERR_BLOCKED_BY_CLIENT". Thanks @rob-w. – Dom Oct 19 '17 at 16:10
-
Continues to work, especially useful for me since I use something other than AdBlock. Thanks! – Vlad Iliescu Jun 09 '18 at 17:41
-
Continues to work till Jan 2023 Adblock answer is obsolete now – Madhur Bhaiya Jan 24 '23 at 17:12
AdBlock for Chrome can be used to block JS files.....
https://chrome.google.com/webstore/detail/gighmmpiobklfepjocnamgkkbiglidom
...Click on the AdBlock icon and select "Show the resource list" and look for the JS you want to block and tick the box next to it and make your selections.
Note
In settings, "I'm an advanced user, show me advanced options." should be selected.

- 8,366
- 2
- 34
- 27
-
2yes, not the user friendliest solution, but works as a charm. Please update answer with note, that in settings, "I'm an advanced user, show me advanced options." should be selected. Authors of firebug and developer toolbar for FF should take a notice ;) – henrijs Mar 14 '12 at 11:03
-
10"Show the resource list" not there even after enabling "I'm an advanced user, show me advanced options." ? obsolete solution? – Mahesha999 Feb 12 '17 at 20:15
I believe this is a limitation of the way a browser debuggers work. It is probably more easy to just comment out the files in the code and test it.

- 2,675
- 1
- 22
- 40
-
-
true, are they maybe loaded from a seperate domain? Then you can change the dns (of hosts file locally) to disable the js files alltogether? – Rody Mar 14 '12 at 09:15