Why does chrome.webRequest.OnBeforeRequest fire before chrome.webNavigation.onBeforeNavigate

740 views
Skip to first unread message

BenR

unread,
Jul 16, 2015, 5:50:07 PM7/16/15
to chromium-...@chromium.org
Hopefully my question is simple. How can webRequest.onBeforeRequest know there is a request to receive before chrome.webNavigation.onBeforeNavigate has completed? Doesn't the browser need to at least query the web server to get any request at all?

Trying to understand this logically. Here is the very simple code:
window.Test = function (url) {
    chrome.tabs.create({ url: "" }, function (tab) {
        chrome.webNavigation.onBeforeNavigate.addListener(function (details) {
            console.log("chrome.webNavigation.onBeforeNavigate hit on " + details.timeStamp);
        });

        chrome.webRequest.onBeforeRequest.addListener(function (details) {
            console.log("chrome.webRequest.onBeforeRequest hit on " + details.timeStamp);
        }, {
            tabId: tab.id,
            urls: ["<all_urls>"]
        });

        chrome.tabs.update(tab.id, {
            url: url
        });
    });
};


Then if I hit a very simple site like www.steam.com, which has only two requests, I get this console response:
chrome.webRequest.onBeforeRequest hit on 1437083141916.896
chrome.webNavigation.onBeforeNavigate hit on 1437083141916.906
chrome.webRequest.onBeforeRequest hit on 1437083141940.385

Here is the manifest, if it's important
{
  "background": {
    "persistent": true,
    "scripts": [
      "temp.js"
    ]
  },
  "manifest_version": 2,
  "name": "Sharkbait",
  "permissions": [
    "<all_urls>",
    "webNavigation",
    "webRequest"
  ],
  "version": "1.0"
}


Many thanks,
Ben

PhistucK

unread,
Jul 17, 2015, 4:49:55 AM7/17/15
to BenR, Chromium-extensions
Perhaps this is done to accommodate 204 responses. I think those cancel the navigation.


PhistucK

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/578b39e4-3f3d-402a-b7de-fd789202a28a%40chromium.org.
For more options, visit https://groups.google.com/a/chromium.org/d/optout.

Reply all
Reply to author
Forward
0 new messages