Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable single javascript file with addon or extension [closed]

Tags:

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?

like image 445
henrijs Avatar asked Mar 14 '12 08:03

henrijs


People also ask

How do I disable certain JavaScript?

Press Ctrl + Shift + P (Windows, Linux) or Command + Shift + P (macOS) to open the Command Menu. Start typing javascript , select Disable JavaScript, and then press Enter to run the command. JavaScript is now disabled.

How do I disable a specific script?

In the Internet Options window, click the Security tab. In the Security tab, click Custom Level button. Scroll down the list (close to the bottom) and locate Active Scripting. Select Disable, Enable, or Prompt to adjust your JavaScript settings.


2 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.

  1. Create a new directory.
  2. Create the files below.
  3. 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).

like image 125
Rob W Avatar answered Sep 24 '22 01:09

Rob W


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.

like image 35
PAEz Avatar answered Sep 24 '22 01:09

PAEz