Closed
Bug 579764
Opened 14 years ago
Closed 14 years ago
notify observers after the document element has been created but before script inside it has run
Categories
(Core :: DOM: Core & HTML, defect)
Core
DOM: Core & HTML
Tracking
()
RESOLVED
FIXED
Tracking | Status | |
---|---|---|
blocking2.0 | --- | beta5+ |
People
(Reporter: myk, Assigned: sicking)
References
Details
(Keywords: dev-doc-complete)
Attachments
(1 file, 1 obsolete file)
(deleted),
patch
|
jst
:
review+
myk
:
feedback+
|
Details | Diff | Splinter Review |
Two common use cases for the upcoming page mods API of the Jetpack SDK are:
1. add properties to a page's global object (f.e. an experimental camera API);
2. manipulate the DOM of a page using a JavaScript library like jQuery.
To make the page mods API as simple as possible to learn and use, it should be possible to do both things with a consistent API, ideally even in the same mod, via something like this simplified sample code:
PageMod({
scriptURL: [url("my-script-that-adds-property.js"),
url("jquery.js"),
url("my-script-that-manipulates-dom.js")]
...
});
We can support the first use case by loading the script on content-document-global-created, per bug 549539, but that doesn't support the second use case, because jQuery assumes that document.documentElement exists, as it is normally loaded by a web page via a <script> tag, by which time the document element has been created.
To support our ideal API, it should be possible to run page mod code at the point in time after which the document element for a page has been created but before any of the scripts specified by the page have run.
Comment 1•14 years ago
|
||
Note that right now there may not be such a time. Making such a time exist may well involve parser changes for both xml and html.
Assignee | ||
Comment 2•14 years ago
|
||
Another problem is, are we fine with notifying into a jetpack from the content thread, and blocking until the jetpack is done handling that notification?
I guess it's ok once we have process separation between chrome and content? But before then? What do we do elsewhere?
Reporter | ||
Comment 3•14 years ago
|
||
(In reply to comment #2)
> Another problem is, are we fine with notifying into a jetpack from the content
> thread, and blocking until the jetpack is done handling that notification?
Don't we already do this for content-document-global-created?
Assignee | ||
Comment 4•14 years ago
|
||
content-document-global-created is just a observerService notification. But if someone calls into jetpacks when they fire and block until the jetpack returns, then yes, we are.
Is that the case?
Reporter | ||
Comment 5•14 years ago
|
||
(In reply to comment #4)
> content-document-global-created is just a observerService notification. But if
> someone calls into jetpacks when they fire and block until the jetpack returns,
> then yes, we are.
>
> Is that the case?
Yes. When the notification fires, if a Jetpack-based addon has registered some code to be run alongside the page being loaded (via the Page Mods API or some other API with access to content pages), an observer creates a sandbox with access to the page's JS context and loads code provided by the addon into it.
However, once Jetpack-based addons run in separate "jetpack" processes, this particular chunk of work will probably still happen in the content process, so there will be no need for the content process to block waiting for the jetpack process (which, as understand it from conversations with bsmedberg, is tricky to implement and requires some bridging infrastructure).
Assignee | ||
Updated•14 years ago
|
Assignee: nobody → jonas
blocking2.0: --- → beta5+
Assignee | ||
Comment 6•14 years ago
|
||
This is an untested patch.
Assignee | ||
Comment 7•14 years ago
|
||
Comment on attachment 469280 [details] [diff] [review]
v0.1
Err.. nevermind
Attachment #469280 -
Attachment is obsolete: true
Assignee | ||
Comment 8•14 years ago
|
||
Ok, this one should work better.
Reporter | ||
Comment 9•14 years ago
|
||
Comment on attachment 469310 [details] [diff] [review]
Patch v0.2
I tested this patch with my Jetpack SDK changes in bug 590968, attachment 469514 [details] [diff] [review], and it worked fine. I was able to load jQuery as a content script on document-element-inserted without exceptions being thrown, and it behaved as expected.
Attachment #469310 -
Flags: feedback+
Assignee | ||
Updated•14 years ago
|
Attachment #469310 -
Flags: review?(jst)
Updated•14 years ago
|
Attachment #469310 -
Flags: review?(jst) → review+
Comment 10•14 years ago
|
||
Jonas: is this safe to land or is there a high risk of regression from it? If so, I'd rather push it to beta6+; what say you?
Assignee | ||
Comment 11•14 years ago
|
||
This was actually already checked in friday night:
http://hg.mozilla.org/mozilla-central/rev/34afbe32fb0e
Status: NEW → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
Updated•14 years ago
|
Keywords: dev-doc-needed
Blocks: 642145
Comment 12•14 years ago
|
||
Documented here:
https://developer.mozilla.org/en/Observer_Notifications#Documents
And mentioned on Firefox 4 for developers.
Keywords: dev-doc-needed → dev-doc-complete
Updated•6 years ago
|
Component: DOM → DOM: Core & HTML
You need to log in
before you can comment on or make changes to this bug.
Description
•