How to detect URLs loading in the background in Mozilla Add-on?

I am writing a script for Mozilla Firefox Add-on to detect the
certain URLs loading in the background and modify the content using
pageMod.PageMod. Currently I am using following script:

var pageMod = require("sdk/page-mod");
    pageMod.PageMod({
      include: ["*.maxcdn.com","*.googleapis.com","192.168.1.1"],
      contentScript: 'window.alert("This website is using CDN/localhost");'
    });

The problem with above script is it is only detecting the parent (main URL) and not the scripts/css loading in the background.

AFAIK… the contentScript fires after the DOM load.
In order to get those external script, you need to set up an observer for http-on-modify-request
More info: system/events & Observer Notifications

1 Like

I think observer notifications is a great idea. If you don’t want to use it because it cannot be limited to a specific tab then here’s an alternative method. To limit to a tab you can use nsIWebProgressListener with flag to listen to background:

Here is how i used it here -

When you addProgressListener you have to include the flag.

1 Like