Search code examples
firefoxfirefox-addonfirefox-addon-sdk

Bootstrapped Firefox extension: how to capture navigation events before a page request?


I'm building a bootstrapped Firefox extension using the Mozilla add-on SDK (not a traditional XUL addon like other similar questions).

I'd like to capture navigation events before they issue HTTP requests.

I've been using pageMod.PageMod({contentScriptWhen: "start", onAttach: MY_CODE_HERE}) - however, it only triggers onAttach after the page is loaded.

That is reinforced by the SDK documentation:

contentScriptWhen = "start": load content scripts immediately after the document element is inserted into the DOM, but before the DOM content itself has been loaded

On a bootstrapped Firefox extension, is it possible to capture navigation events before the page loads?


Solution

  • You can intercept, and handle, requests via the SDK's system events: How to handle every request in a FF extension

    You don't need a pagemod, as this is on the Firefox level, not the per-tab level like the pagemod.