bugzilla.mozilla.org has resumed normal operation. Attachments prior to 2014 will be unavailable for a few days. This is tracked in Bug 1475801.
Please report any other irregularities here.

Add a way to "inject" JS into a document earlier than onload

RESOLVED DUPLICATE of bug 342715

Status

()

Core
DOM: Events
--
enhancement
RESOLVED DUPLICATE of bug 342715
11 years ago
11 years ago

People

(Reporter: mkaply, Unassigned)

Tracking

Trunk
x86
Windows XP
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

11 years ago
Best way to describe this is a use case.

If you wanted to emulate the JS functionality of other browsers, you would typically create a component and add new JS functionality to the category manager.

However, if you wanted some of that functionality to be site specific, you couldn't do it in the category manager - you'd want it to only be there for a certain site.

To do this, you would want to listen for events and then at the right time, inject the javascript.

Unfortunately, the earliest you can do this today is onload or DOMContentLoaded. This is too late, since a lot of pages check for other browser APIs earlier than that.

There should be a way to listen for an event that is early enough that you can get the page JS context and put new APIs into it before the page starts parsing JS.

Attached is an attempt from OpenSUSE to solve this problem (this is open source and in the source code for OpenSUSE)

It can be utilized with a listener like this:

browser.addProgressListener(foo, I.nsIWebProgress.NOTIFY_STATE_DOCUMENT);

and then in the onStateChange

if (flags & Components.interfaces.nsIWebProgressListener.STATE_TRANSFERRING)
{
  if webprogress.DOMWindow.location.href is a page I want to do this on, 

get webprogress.DOMWindow and do magic with eval, etc.
    
}


Is this a good/bad idea? Is there a better way to do this?

Comment 1

11 years ago
This could be fun for Greasemonkey too.
(Reporter)

Comment 2

11 years ago
Didn't realize there was already a bug.
Status: NEW → RESOLVED
Last Resolved: 11 years ago
Resolution: --- → DUPLICATE
Duplicate of bug: 342715
You need to log in before you can comment on or make changes to this bug.