1

I've spent a good few hours trying to crack this myself, having analysed a bunch of other people's work (this is the latest one I've tried to hack Block URL with a specific word somewhere in the subdomain ), and have come up none the wiser.

I feel like the js shouldn't really be that complex, I'm just trying to block a webpage and surface an error message in its place.

This is where I've netted out atm:

chrome.declarativeWebRequest.onRequest.addRules({
  id: 'some rule id',
  conditions: [
    new chrome.declarativeWebRequest.RequestMatcher({
      url: {
        host: 'www.dailymail.com'
      }
    })
  ],

  actions: [
    new chrome.declarativeWebRequest.CancelRequest()
  ]
});
Community
  • 1
  • 1
CWB
  • 11
  • 2

1 Answers1

0

The answer at Block URL with a specific word somewhere in the subdomain works as expected. When it does not work, follow the following steps to troubleshoot the problem:

  1. Open the background page's console and look for error messages.
    Search for the error message on Google, and try to understand the recommended results. Trustworthy sources include Stack Overflow, the extension documentation, Chromium's bug tracker, the chromium-extensions and chromium-apps mailing lists.

  2. Check whether you have added the correct permissions to your manifest file.

  3. If you have just added the new permissions, make sure that you have reloaded the extension (e.g. by clicking on Reload at chrome://extensions/).

With the information you've provided, I can think of three reasons for failure:

  1. Are you using Chromium beta, Chromium dev (or even Canary)? If not, then either install Chrome from one of these channels, or use the webRequest API instead. The declarativeWebRequest API is currently not available on the stable channel, only on the beta and developer channels.
  2. url is an object of the type UrlFilter. There is no property called "host", if you want to match an exact host, use hostEquals, like this:

    url: {
        hostEquals: 'www.dailymail.com'
    }
    
  3. You have not added the correct permissions. To get your demo to work, you need to declare the declarativeWebRequest and *://www.dailymail.com/* permissions in the manifest file.
Community
  • 1
  • 1
Rob W
  • 341,306
  • 83
  • 791
  • 678