Closed Bug 620700 Opened 14 years ago Closed 13 years ago

Add an API for intercepting network requests and responses

Categories

(Add-on SDK Graveyard :: General, enhancement, P2)

enhancement

Tracking

(Not tracked)

RESOLVED INVALID
Future

People

(Reporter: xstevens, Unassigned)

Details

I would like to see a pre-process hook added for the addons.  This would allow addons to peek at the page before subsequent requests are made for images, scripts, etc.
Hmm, I'm not sure what this is asking for.  Can you elaborate?
I was talking to Daniel Buchner at work week.  Basically I want the ability to inspect/manipulate the DOM before actual network requests are made for images and external scripts.
When you say "inspect/manipulate the DOM", do you mean the DOM of a web page?

The Page Mods API lets an addon run "content scripts" that manipulate the DOM of a web page whose URL matches a specified URL pattern at one of two points in time:

* when contentScriptWhen = "start", then after the document element is inserted into the DOM tree, but before any scripts, stylesheets, or images have started loading;
* when contentScriptWhen = "ready", then after the DOM tree has been constructed, which is after scripts have finished loading, and perhaps after stylesheets and images have started loading, but probably before stylesheets and images have finished loading.

I don't know how it would be possible to access the DOM after the DOM tree has been constructed but before network requests have been made for external scripts given the current web model, since scripts are loaded synchronously as part of the parsing of the document into a DOM tree.  So the DOM tree is not fully parsed until after all scripts have been loaded.

It might be possible to access the DOM before network requests have been made for images, however, since those load asynchronously.  It's not clear whether such network requests have been made by the time contentScriptWhen = "ready".

Perhaps if you describe your specific use case, we can help figure out if it's possible to satisfy it!
I put Daniel on CC because perhaps he can describe this better than I can.
I believe Xavier wants the ability to analyze oand modify various content streams before they are evaluated by the built-in rendering mechanisms of the browser.

Examples:

Analyzing the content of a web page to delete img tags before the HTML rendering engine parses the stream and creates DOM representations of it.

Listening to network I/O for the purpose of modifying, filtering, or blocking requests, etc.
Ah, ok, now I understand!  Hmm, I'm not sure whether this is possible at the moment.  There might be a way to plug into the relevant network streams.
The notifications service sends notifications on HTTP requests and responses.  You can use the SDK's low-level observer-service API to hook into them:

https://developer.mozilla.org/en/Observer_Notifications#HTTP_requests

This would make a cool, small, high-level API though.  I'm not 100% sure, but I think Adblock Plus relies on these notifications to block ad-related requests before they're made.  If that's true, such an API would go some way in enabling people to write proper ad-blocking add-ons with the SDK (like, say, Adblock Plus!).
Component: Jetpack SDK → General
OS: Mac OS X → All
Product: Mozilla Labs → Add-on SDK
QA Contact: jetpack-sdk → general
Hardware: x86 → All
Summary: Add pre-process hook for Addons → Add an API for intercepting network requests and responses
This is an API that is requested frequently. I think it would be nice to have an API implementation that looks a lot like Page Mods, where you would declare domains to observe network traffic on, and a param for what type of traffic/files to watch for (if possible) - here is a bit of pseudo code to illustrate this: http://paste.mootools.net/f5d33b5a1
Priority: -- → P2
Target Milestone: --- → Future
This is wanted, but it'll probably work better for now as a Feature page.
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.