This can be done quite easily via a Chrome extension, using the webRequest API. The example below blocks all external scripts. Replace
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: [""], // 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",
""
]
}
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).