Search code examples
javascriptfirefox-addonfirefox-addon-sdk

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.


Solution

  • WebRequest.jsm can instrument all requests.

    There also are lower-level primitives (http observers and content policies) on which WebRequest is built. But they are more difficult to implement.