W3C home > Mailing lists > Public > public-webapps@w3.org > April to June 2012

Re: Should MutationObservers be able to observe work done by the HTML parser?

From: Mihai Parparita <mihaip@chromium.org>
Date: Fri, 15 Jun 2012 18:15:37 -0700
Message-ID: <CAHerz5d9naZ2SxEa076dVPbmj+2oq1jHKQERXsv26O3FjY4ePQ@mail.gmail.com>
To: Adam Klein <adamk@chromium.org>
Cc: WebApps WG <public-webapps@w3.org>, Olli@pettay.fi, Rafael Weinstein <rafaelw@chromium.org>
I used MutationObservers for the first time last night (in Chrome),
and I was surprised by this behavior. I was working on something that
transmogrified one node into another, so having observers file during
parsing would have helpful. Otherwise something like:

<script>var observer = new MutationObserver(/* observer that
manipulates <foo> tags */);</script>
  /* code that acts on foo tags */

If I have to use DOMContentLoaded, then the code in the second
<script> block would get a chance to operate on <foo> before my
observer had had a chance to transmogrify it.


On Fri, Jun 15, 2012 at 4:36 PM, Adam Klein <adamk@chromium.org> wrote:
> Re-sending from correct address:
> On Fri, Jun 15, 2012 at 4:35 PM, Adam Klein <adamk@google.com> wrote:
>> This code alerts in Firefox but not in Chrome:
>> <!DOCTYPE html>
>> <body>
>>   <script>
>>     var observer = new MutationObserver(function(r) {
>>       alert(r);
>>     });
>>     observer.observe(document.body, {childList: true, subtree: true});
>>   </script>
>>   <p>Hello, World</p>
>> </body>
>> In WebKit's implementation, we had assumed that MutationObservers were
>> meant to observe changes after page load (and I personally thought that we'd
>> specced it that way, by putting it in DOM4, not HTML). But it seems the
>> Mozilla implementors made a different assumption. But what should happen?
>> IMHO, it may not be worth the gain may not be worth the possible
>> performance degradation. If script wants to find out what the parser put on
>> the page, it should wait for DOMContentLoaded. But I can imagine a use case
>> where script might want to find out about the parser's work during load.
>> In any case, we should try to come to a decision about this, since this
>> seems to be the one major divergence between the existent implementations of
>> MutationObservers.
>> Thoughts?
>> - Adam
Received on Saturday, 16 June 2012 01:16:07 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 18:13:34 UTC