0

I supposed that every request will invoke onBeforeRequest, but it seems not. Below is an example from google doc, and I insert console.log to see if any request invoke onBeforeRequest.

chrome.webRequest.onBeforeRequest.addListener(
    function(details) {
      console.log(details.url);
      return {cancel: details.url.indexOf("://www.evil.com/") != -1};
    },
    {urls: ["<all_urls>"]},
    ["blocking"]);

Some websites, for example, Facebook, will not print anything on the console.

What kind of requests will be captured by onBeforeRequest?

Nai
  • 69
  • 6

1 Answers1

0

What are your permissions? The API requires that you have host permissions for all URLs you want to catch.

For instance, the above example requires the following:

"permissions" : [
  "webRequest",
  "webRequestBlocking",
  "<all_urls>"
]
Xan
  • 74,770
  • 16
  • 179
  • 206
  • maybe its going through push. i havent been able to catch push notifications that are received in sockets and such. some sites receive the entire update like that without doing another ajax. – Zig Mandel Aug 05 '15 at 19:35
  • @ZigMandel True, it will not catch WebSocket traffic, but OP says "will not print _anything_" – Xan Aug 05 '15 at 20:07
  • so how to catch websockets? maybe I should finally ask a question here :) – Zig Mandel Aug 05 '15 at 20:10
  • @ZigMandel Sadly, I think only `chrome.debugger` or `chrome.devtools` expose those. See [this question](http://stackoverflow.com/q/31181651/934239). – Xan Aug 05 '15 at 20:11
  • I only add "http://*/*" to my permission, that's why it could not block Facebook. Thank you! – Nai Aug 06 '15 at 02:42