--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.
Anything you can accomplish with Mutation Events, you should be able
to accomplish with Mutation Observers -- and it'll be faster to boot.
It already looks to me like you'll likely to want to use the Mutation
Summary library for both of these cases.
It looks like you only really care if elements are inserted, so
MutationSummary's "element query" will suit you:
var summaryObserver = new MutationSummary({ callback: handleChanges,
queries: [{ element: "*" }] });
function handleChanges(summaries) {
var elementSummary = summaries[0];
// look for added elements that are significant:
processAddedElements(elementSummary.added);
}
I'm curious about your use cases. Perhaps you can explain a bit more
about what is going on below (i.e. what changes you expect to be
seeing that you are responding to)?
On Fri, Feb 17, 2012 at 7:30 AM, Mohamed Mansour <m...@chromium.org> wrote:
> Hi Ernest,
>
> Would that allow me to rewrite this with Mutation Events?
> https://github.com/mohamedmansour/extended-share-extension/blob/master/js/extended_injection.js#L54
This appears to be listening to DOMNodeInserted and handling two cases:
1) If the inserted node's *grandparent* is the #contentPane, =>
renderAllItems(e.target)
2) If the inserted node is an element with an id that starts with
'update' => look for 'div > div:nth-of-type(3)' and
renderItem(actionBar).
>
> or even this?
> https://github.com/mohamedmansour/static-share-for-google-plus-extension/blob/master/static_share.js#L43
I can't exactly make out what's happening here.
It does look like you are adding a className to the element here to
prevent yourself from doing the same thing twice ('crx-lazy-box') in
response to DOMNodeInserted. If that's true then if you use the
MutationSummary, you may be able to ditch this because it will only
ever tell you about elements that truly *new* within the area of the
document you are observing.
If you need to react to those changes by making more changes -- won’t you hear about those changes the next time it calls you back? Not unless you ask for that.
It's simply a case of the extension not attempting to implement it.
It's totally possible -- it's just left as an exercise to the user of
the MutationSummary library.
The basic approach would be to just use a separate instance of
MutationSummary to observe each iframe's contentDocument.
>
> On Feb 17, 4:48 am, Ernest Delgado <erne...@google.com> wrote:
>> Many extensions are currently using Mutation Events to trigger some
>> action in the extension when a change in the page DOM occurs. Mutation
>> Events has been deprecated in the DOM spec and will be going away at
>> some point.
>>
>> Mutation Observers are faster, safer & fully implemented in Chrome
>> (Mutation Events were never fully implemented). Mutation Observers are
>> available in Chrome Beta and are on track to make it to Chrome 18.
>>
>> Thanks to Rafael Weinstein, we've open-sourced a JS Library that most
>> use cases will want to use: code.google.com/p/mutation-summary(also
>> contains more info about Mutation Observers)
>>
>> If you are currently using Mutation Events and have any question about
>> it feel free to drop a question here, although we encourage to use our
>> StackOverflow channel instead:http://stackoverflow.com/questions/tagged/google-chrome-extension
>