What I have so far:
manifest.json
{ "name": "Testing", "version": "0.1", "manifest_version": 2, "description": "Hi there.", "background": { "scripts": ["background.js"] }, "icons": { "128" : "images/test.png" }, "browser_action": { "default_icon": "images/test2.png", "default_title": "test" }, "permissions": [ "webRequest", "webRequestBlocking", "https://www.google.com/*", "http://www.dictionary.com/*" ] } background.js
chrome.webRequest.onBeforeRequest.addListener(function(details) { return {cancel: true}; }, {urls: ["https://www.google.com", "http://www.dictionary.com/*"]}, ["blocking"]); I was hoping that by loading this unpacked extension, it would "block" the listed websites (testing with Google.com and dictionary.com). I'm not sure how the blocking functionality actually works, but I figured either the website wouldn't load or it would display some sort of general error.
However, nothing seems to happen, so I'm guessing that either my understanding of "blocking" is flawed and/or my code isn't written correctly. I based my code off these references:
https://developer.chrome.com/extensions/examples/extensions/catblock/manifest.json https://developer.chrome.com/extensions/examples/extensions/catblock/background.js https://developer.chrome.com/extensions/webRequest
"The following example achieves the same goal in a more efficient way because requests that are not targeted to www.evil.com do not need to be passed to the extension:
chrome.webRequest.onBeforeRequest.addListener( function(details) { return {cancel: true}; }, {urls: ["*://www.evil.com/*"]}, ["blocking"]); " This is my 1st time attempting to make a chrome extension, and I'm not really familiar with html or javascript, so apologies if I'm way off the mark with my implementation.
https://www.google.comis not a valid pattern. Simply add/*Reloadaction link on chrome://extensions page.function blockRequest(details) { return {cancel: true}; } function updateFilters(urls) { if(chrome.webRequest.onBeforeRequest.hasListener(blockRequest)) chrome.webRequest.onBeforeRequest.removeListener(blockRequest); chrome.webRequest.onBeforeRequest.addListener(blockRequest, {urls: ["*://*.google.com/*"]}, ['blocking']); } updateFilters();Not sure why the previous implementation didn't work./*. No need to remove the listener. It does nothing because the API doesn't register a second copy of the listener anyway. If it doesn't work for you, there's something else you're doing wrong.