I\'m re-posting my question from Chromium-extensions google group here.
In my extension, I want to cancel some webRequests based on url pattern. My problem is that,
You should use "javascript:" url instead :
{
redirectUrl:"javascript:"
}
Redirect to a page which replies with HTTP status code 204, e.g. https://robwu.nl/204 This is my website, and I do not log any traffic to this URL.
The specification demands the following behavior for a response with HTTP status 204:
If the client is a user agent, it SHOULD NOT change its document view from that which caused the request to be sent. This response is primarily intended to allow input for actions to take place without causing a change to the user agent's active document view, although any new or updated metainformation SHOULD be applied to the document currently in the user agent's active view.
Here is a simple example, an extension that silently blocks all requests to YouTube:
chrome.webRequest.onBeforeRequest.addListener(function(details) {
var scheme = /^https/.test(details.url) ? 'https' : 'http';
return { redirectUrl: scheme + '://robwu.nl/204' };
}, {
urls: ['*://www.youtube.com/*'] // Example: Block all requests to YouTube
}, ['blocking']);
This example redirects to http://robwu.nl/204 or https://robwu.nl/204 depending on the requests's scheme, to avoid mixed content warnings.
To get this example to work, you need to declare the webRequest, webRequestBlocking and host permissions for the site in the manifest file.
return {redirectUrl: 'javascript:void(0)'};