I am not very well acquainted with JS and chrome*api's but to my understanding chrome.webNavigation.onDOMContentLoaded is suppose to trigger an event when html response's DOM creation is completed and page is yet to be rendered on the browser.
My objective is to parse the response as soon as it is downloaded completely with all it's scripts but before the page is rendered on the browser i.e., page rendering should wait until I am done with the parsing of the response.
I have written a small chrome extension as a step to achieve above objective which pops up an alert message as a result of event that is triggered as part onDOMContentLoaded.
Manifest file:
Code:
{
"manifest_version": 2,
"name": "Informant",
"version": "1.0",
"background": {
      "scripts": [
          "background.js"
      ]
  },
"permissions": [
  "tabs",
  "*://*/*",
  "webNavigation"
]
}


background.js
Code:
var dothis = function() {
    alert("Why is this so?");
};
chrome.webNavigation.onDOMContentLoaded.addListener(dothis);
To my understanding for every response there should be a single onDOMContentLoaded event and therefore there should be single alert message popping up but to my surprise the alert message pop ups multiple time. Could anyone please explain this? Or is there any fault in the code itself? Or in the understanding?
The behavior is though fluctuates on different sites. Try songsterr . com

Also, please suggest how to achieve main objective, if possible.

------------------------------------------------------------------------------------------------------


A short guide to reproduce this scenario:
1. Save the manifest file as "manifest.json" and javascript file as "background.js" in folder name it may be "chromeextension".
2. Go to chrome's extension page.
3. Enable the developer's mode.
4. Click on "Load unpackaged extension..." button to select the above folder and you are done.
5. Visit any website to see the alert messages popping up!