H Everyone, could you kindly help me in the following?
I’d like to write an extension that blocks Javascript from running on specific sites. I was thinking I can use the onBeforeRequest event for this to catch the requestBody before the page loads and then remove every script tag from it. I cannot get it working. I have the following code so far:
manifest.json:
{
“description”: “just some test”,
“manifest_version”: 2,
“name”: “testttt”,
“version”: “1.0”,
“icons”: {
“48”: “icon.svg”
},
"applications": {
"gecko": {
"id": "testttt@mozilla.org",
"strict_min_version": "45.0"
}
},
"permissions": [
"webRequest", "webRequestBlocking"
],
"background": {
"scripts": ["background.js"]
},
"content_scripts": [
{
"matches": ["*://mydomain.com/*"],
"js": ["test.js"]
}
]
}
test.js:
document.body.style.border = “20px solid orange”;
background.js:
browser.webRequest.onBeforeRequest.addListener(
function(requestDetails){
console.log(“hello”);
alert(22);
},
{urls: [“https://mydomain.com/*”]},
[“requestBody”, “blocking”]
);
test.js does work, however background.js does not. There is no log of “hello” in the log panel that I open up with key Ctrl+Shift+J. There is no popup box from alert either.
Could you tell me what’s wrong and how I could achive to block scripts on specific sites writing my own WebExtension?
I’m on FF 57 beta3 but I have the same reault on 55.0.3 too.
I’m testing my webext using the about:debugging#addons page and load it there using the reload button for changes.
Thanks.